package com.pan.kang.dao.impl;

import com.pan.kang.dao.IAccComprehensiveQueryDao;
import com.pan.kang.model.cons.AccComprehensiveQueryDaoConst;
import com.pan.kang.model.cons.AccComprehensiveQueryQtySqlDaoConst;
import com.pan.kang.model.domain.AccBookBO;
import com.pan.kang.support.SqlResource;
import com.pan.kang.util.AccConditionUtils;
import com.pan.kang.util.ConvertUtil;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.pan.kang.util.DBUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;


@Component
public class AccComprehensiveQueryDao implements IAccComprehensiveQueryDao {

    public static final String NOT_SAME_MONEY_COL = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
    public static final String SAME_MONEY_COL = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
    public static final String NOT_SAME_MONEY_COL_MINUS = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) * -1 QCYE_BWB, SUM(A.CR_AMT_Y) * -1 SUM_J_BWB, SUM(A.DR_AMT_Y) * -1 SUM_D_BWB";
    public static final String SAME_MONEY_COL_MINUS = "SUM(A.CR_BALP_S - A.DR_BALP_S) * -1 QCYE_BWB, SUM(A.DR_AMT_TOT) * -1 SUM_J_BWB, SUM(A.CR_AMT_TOT) * -1 SUM_D_BWB";
    public static final String NOT_SAME_MONEY_COL_FOR_CUR_MINUS = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) * -1 SUM_D_BWB";
    public static final String NOT_SAME_MONEY_COL_FOR_CUR_MY_SQL_MINUS = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) * -1 SUM_D_BWB";
    public static final String SAME_MONEY_COL_FOR_CUR_MINUS = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) * -1 SUM_D_BWB";
    public static final String SAME_MONEY_COL_FOR_CUR_MY_SQL_MINUS = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) * -1 SUM_D_BWB";
    public static final String OSET_NOT_SAME_MONEY_COL_FOR_CUR_MINUS = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) * -1 SUM_D_BWB";
    public static final String OSET_NOT_SAME_MONEY_COL_FOR_CUR_MY_SQL_MINUS = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) * -1 SUM_D_BWB";
    public static final String OSET_SAME_MONEY_COL_FOR_CUR_MY_SQL_MINUS = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) * -1 SUM_D_BWB";
    public static final String OSET_SAME_MONEY_COL_FOR_CUR_MINUS = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) * -1 SUM_D_BWB";
    public static final String NOT_SAME_MONEY_COL_FOR_CUR = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
    public static final String SAME_MONEY_COL_FOR_CUR = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
    public static final String OSET_NOT_SAME_MONEY_COL_FOR_CUR = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
    public static final String OSET_SAME_MONEY_COL_FOR_CUR = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
    public static final String DIM_NOT_SAME_MONEY_COL = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
    public static final String DIM_SAME_MONEY_COL = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
    public static final String DIM_NOT_SAME_MONEY_COL_FOR_CUR = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
    public static final String DIM_SAME_MONEY_COL_FOR_CUR = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
    public static final String DIM_OSET_NOT_SAME_MONEY_COL_FOR_CUR = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
    public static final String DIM_OSET_SAME_MONEY_COL_FOR_CUR = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
    public static final String NOT_SAME_MONEY_COL_FOR_CUR_MY_SQL = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
    public static final String SAME_MONEY_COL_FOR_CUR_MY_SQL = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
    public static final String OSET_NOT_SAME_MONEY_COL_FOR_CUR_MY_SQL = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
    public static final String OSET_SAME_MONEY_COL_FOR_CUR_MY_SQL = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
    public static final String DIM_NOT_SAME_MONEY_COL_FOR_CUR_MY_SQL = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
    public static final String DIM_SAME_MONEY_COL_FOR_CUR_MY_SQL = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
    public static final String DIM_OSET_NOT_SAME_MONEY_COL_FOR_CUR_MY_SQL = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
    public static final String DIM_OSET_SAME_MONEY_COL_FOR_CUR_MY_SQL = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
    public static final String FIND_WD_RELATION = " SELECT DIM_TYPE type,FIE_NAM WDNAME from ACC_VOU_DIM_DEF where FIE_NAM  IN (:WDNAME) GROUP BY DIM_TYPE,FIE_NAM ";
    public static final String FIND_PROFIT_LOSS_MONEY = "SELECT NULL ZDNAME, ''{1}'' COMPID, MX.ACC_SUB KMID, 0 QCYE, 0 QCYE_BWB, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.FOR_CY_AMT ELSE 0 END) * -1 SUM_WB_J, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_J, SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.FOR_CY_AMT ELSE 0 END) * -1 SUM_WB_D,  SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_D, 0 QMYE, 0 QMYE_BWB, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.FOR_CY_AMT ELSE 0 END) * -1 SUM_WB_LJ, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_LJ, SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.FOR_CY_AMT ELSE 0 END) * -1 SUM_WB_LD,  SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_LD, MAIN.ACC_PERIOD ACCOUNT_ID{5} FROM ACC_VOUCH{0} MAIN JOIN ACC_VOUCH_DTL{0} MX ON MAIN.BILL_ID = MX.BILL_ID JOIN GT_KMDESTTAB D ON D.IID = MX.ACC_SUB AND D.LEAF = 1 JOIN ACC_MON_CAR_ITEM_STAT C ON MAIN.BILL_ID = C.BILL_ID  WHERE MAIN.FINA_ORG = ''{1}'' AND MAIN.ACC_PERIOD = {2}   AND MAIN.FINISH_SUM_FLAG = 1  AND MAIN.ACC_BOOK = 0 {7} {3} {4} {6}";
    public static final String FIND_ALL_CURRENCY = " UNION  SELECT '''' ZDNAME, ''{1}'' COMPID, MX.ACC_SUB KMID, 0 QCYE, 0 QCYE_BWB, 0 SUM_WB_J, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_J, 0 SUM_WB_D, SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_D, 0 QMYE, 0 QMYE_BWB, 0 SUM_WB_JL, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_JL, 0 SUM_WB_DL, SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_DL, MAIN.ACC_PERIOD ACCOUNT_ID,-3 MONEY2 FROM  ACC_VOUCH{0} MAIN JOIN ACC_VOUCH_DTL{0} MX ON  MAIN.BILL_ID = MX.BILL_ID JOIN GT_KMDESTTAB D ON D.IID = MX.ACC_SUB AND D.LEAF = 1 JOIN ACC_MON_CAR_ITEM_STAT C ON MAIN.BILL_ID = C.BILL_ID  WHERE  MAIN.FINA_ORG = ''{1}''  AND MAIN.ACC_BOOK = 0 {3}  AND MAIN.ACC_PERIOD = {2}  AND MAIN.FINISH_SUM_FLAG = 1 GROUP BY MX.ACC_SUB,MAIN.ACC_PERIOD";

    public AccComprehensiveQueryDao() {
    }


    private final Logger log = LoggerFactory.getLogger(AccComprehensiveQueryDao.class);

    public void insertCompRelationByRoot(String tyear, String bookId, String compid, Map<String, Object> param) {
        String insertSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SQL_INS_COMPS_QUERY, tyear, bookId, "", compid);
    }

    private void analyzeCompid(Map<String, Object> param) {
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        String compid;
        String pftCompid;
        String compidSql;
        if (mxdwQuery != null && mxdwQuery == 1) {
            compid = ConvertUtil.toString(param.get("detailCompid"));
            pftCompid = ConvertUtil.toString(param.get("accountYear"));
            compidSql = ConvertUtil.toString(param.get("accbookid"));
            param.put("selectcompid", "@HZ_COMPID_TREE");
            this.insertCompRelationByRoot(pftCompid, compidSql, compid, param);
        }

        compid = ConvertUtil.toString(param.get("selectcompid"));
        pftCompid = Objects.isNull(param.get("selectPftCompId")) ? "" : ConvertUtil.toString(param.get("selectPftCompId"));
        compidSql = "";
        String osetCompidSql = "";
        if (StringUtils.isNotEmpty(compid)) {
            if (compid.startsWith("@")) {
                compidSql = " AND A.FINA_ORG = Y.COMPID";
                osetCompidSql = " AND OSET_VOU_UNI = Y.COMPID ";
            } else if (compid.contains(",")) {
                String str = (String)Stream.of(compid.split(",")).map((s) -> {
                    return "'" + s + "'";
                }).collect(Collectors.joining(","));
                String[] compidArr = compid.split(",");
                if (StringUtils.isNotEmpty(pftCompid)) {
                    compidSql = " AND A.PROF_CEN IN ( " + str + " ) ";
                } else {
                    compidSql = " AND A.FINA_ORG IN ( " + str + " ) ";
                }

                osetCompidSql = " AND OSET_VOU_UNI = Y.COMPID ";
            } else {
                if (StringUtils.isNotEmpty(pftCompid)) {
                    compidSql = " AND A.PROF_CEN = '" + pftCompid + "'";
                } else {
                    compidSql = " AND A.FINA_ORG = '" + compid + "'";
                }

                osetCompidSql = " AND A.OSET_VOU_UNI = '" + compid + "'";
            }
        }

        param.put("compidCondition", compidSql);
        param.put("osetCompidCondition", osetCompidSql);
    }

    private String analyzeSelectKm(Map<String, Object> param, String kmitemcode) {
        String returnSql = "";
        StringBuffer kmAndAccJoinTable = new StringBuffer("");
        StringBuffer kmAndDimAndAccSelectSql = new StringBuffer("");
        int isSelectSubject = 0;
        if (StringUtils.isNotEmpty(kmitemcode) && !"null".equals(kmitemcode)) {
            returnSql = this.analyzeSelectKmHaveVale(param, kmitemcode, kmAndAccJoinTable, kmAndDimAndAccSelectSql);
            isSelectSubject = 1;
        } else {
            returnSql = this.analyzeSelectKmNoVale(param, kmAndAccJoinTable, kmAndDimAndAccSelectSql);
        }

        param.put("isSelectSubject", Integer.valueOf(isSelectSubject));
        param.put("kmAndAccJoinTable", kmAndAccJoinTable.toString());
        param.put("kmAndDimAndAccSelectSql", kmAndDimAndAccSelectSql.toString());
        return returnSql;
    }

    private static String findParent(List<String> list, String str) {
        Iterator var2 = list.iterator();

        String s;
        do {
            if (!var2.hasNext()) {
                return str;
            }

            s = (String)var2.next();
        } while(!str.startsWith(s) || str.equals(s));

        return s;
    }

    private List<Object[]> getItemCodes(String itemCodes) {
        List<String> list = Arrays.asList(itemCodes.split(","));
        Map<String, List<String>> grouped = new HashMap();
        Iterator var4 = list.iterator();

        while(var4.hasNext()) {
            String str = (String)var4.next();
            String parent = findParent(list, str);
            ((List)grouped.computeIfAbsent(parent, (k) -> {
                return new ArrayList();
            })).add(str);
        }

        Set<String> strings = grouped.keySet();
        return (List)strings.stream().map((item) -> {
            return new Object[]{item};
        }).collect(Collectors.toList());
    }

    private String analyzeSelectKmHaveVale(Map<String, Object> param, String kmitemcode, StringBuffer kmAndAccJoinTable, StringBuffer kmAndDimAndAccSelectSql) {
        String returnSql = "";
        boolean isShowDesKmDx = ConvertUtil.toBoolean(param.get("isShowDesKmDx"));
        String showItemCodeCon = "";
        List<Object[]> itemObj = this.getItemCodes(kmitemcode);
        Map<String, Object> kmMap = new HashMap();
        kmMap.put("BOOKID", ConvertUtil.toString(param.get("accbookid")));
        kmMap.put("COMPID", ConvertUtil.toString(param.get("unitControl")));
        kmMap.put("TYEAR", ConvertUtil.toString(param.get("accountYear")));
        boolean hasAnalyze = ConvertUtil.toBoolean(param.get("hasAnalyze"));
        if (!hasAnalyze) {
            List<String> replaceTabNameList = new ArrayList();
            log.info(AccComprehensiveQueryDaoConst.INSERT_ALLKM);
            log.info(AccComprehensiveQueryDaoConst.QUERY_KM);
        }

        StringBuilder childItemCodeContion = new StringBuilder(" WHERE OBJ_ITEMCODE IN ( SELECT ITEMCODE FROM GT_KM_IMP ) ");
        StringBuilder showItemCodeContion = new StringBuilder(" WHERE OBJ_ITEMCODE IN ( SELECT ITEMCODE FROM HZBB_KMSUMTMP ");
        showItemCodeContion.append(" )");
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        Integer fzmxQuery = ConvertUtil.toInteger(param.get("fzmxQuery"));
        if (!isShowDesKmDx && (mxdwQuery == null || mxdwQuery != 1) && (fzmxQuery == null || fzmxQuery != 1)) {
            showItemCodeCon = childItemCodeContion.toString();
        } else {
            showItemCodeCon = showItemCodeContion.toString();
        }

        returnSql = this.analyzeKmHaveValeNoOneDim(param, kmAndAccJoinTable, kmAndDimAndAccSelectSql, " AND ITEM_CODE IN ( SELECT ITEMCODE FROM GT_KM_IMP ) ", showItemCodeCon, " START WITH ITEM_CODE IN ( SELECT ITEMCODE FROM GT_KM_IMP  ) ");
        return returnSql;
    }

    private String analyzeKmHaveValeNoOneDim(Map<String, Object> param, StringBuffer kmAndAccJoinTable, StringBuffer kmAndDimAndAccSelectSql, String itemCodeCon, String showItemCodeCon, String starWithCon) {
        String returnSql = "";
        Integer accountIsBetween = ConvertUtil.toInteger(param.get("accountIsBetween"));
        Map<String, Object> params = new HashMap();
        String compId = ConvertUtil.toString(param.get("unitControl"));
        String compIdCon = "AND FINA_ORG = '" + compId + "'";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        Integer isSelectDim = ConvertUtil.toInteger(param.get("isSelectDim"));
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        params.put("TYEAR", accountYear);
        params.put("BOOKID", accbookid);
        String accountIdSelectSql = ConvertUtil.toString(param.get("accountIdSelectSql"));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        String isBottLay = "";
        if (StringUtils.equals("13", ConvertUtil.toString(param.get("kmLevel")))) {
            if (DBUtil.isMySql()) {
                isBottLay = " AND S.IS_BOTT_LAY = 1 ";
            } else {
                isBottLay = " WHERE IS_BOTT_LAY = 1";
            }
        }

        List<String> replaceTabNameList = new ArrayList();
        replaceTabNameList.add("GT_KM_IMP");
        String sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_TREE, "", itemCodeCon, compIdCon, showItemCodeCon, isBottLay);
        log.info(sql);
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer oneDimQueryIsSelectDimValue = ConvertUtil.toInteger(param.get("oneDimQueryIsSelectDimValue"));
        Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        int staCur = ConvertUtil.toInt(param.get("staCur"));
        int moneyType = ConvertUtil.toInt(param.get("moneyType"));
        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        String kmStopCon = "";
        if (mxdwQuery != null && mxdwQuery == 1) {
            returnSql = this.analyzeKmHaveValeNoOneDimDetail(param, kmAndAccJoinTable, kmAndDimAndAccSelectSql, itemCodeCon, showItemCodeCon, starWithCon);
        } else if (returnCount == 0 && ConvertUtil.toString(param.get("selectcompid")).contains(",")) {
            returnSql = this.analyzeKmHaveValeExport(param, kmAndAccJoinTable, kmAndDimAndAccSelectSql, itemCodeCon, showItemCodeCon, starWithCon);
        } else {
            String starWithConn = starWithCon;
            String endAccountId = ConvertUtil.toString(param.get("endAccount"));
            boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
            String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
            String balTable = "ACC_BAL_SUM{1}";
            String vTableName = "";
            if (!isBottomUnit) {
                balTable = "ACC_BAL_SUM{1}_TOP";
            }

            String fileds = null;
            if (StringUtils.isNotEmpty(selectPftCompId)) {
                balTable = "{0}ACC_PFT_BAL_SUM{1}";
                fileds = " T.PROF_CEN FINA_ORG, T.* ";
                if (!isBottomUnit) {
                    balTable = "{0}ACC_PFT_BAL_SUM{1}_TOP";
                }
            }

            String dataOption = ConvertUtil.toString(param.get("dataOption"));
            String moneyCol = " FOR_CUR MONEY2";
            if (dataOption.contains("CONTRADATA")) {
                if ("CONTRADATA1".equals(dataOption)) {
                    balTable = "OSET_BAL_SUM{1}_TOP";
                } else {
                    balTable = "OSET_BAL_SUM{1}";
                }

                compidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
                moneyCol = " FOR_CUR MONEY2 ";
            }

            vTableName = MessageFormat.format(balTable, "", accountYear);
            if (StringUtils.isNotEmpty(selectPftCompId)) {
                vTableName = "(SELECT " + fileds + " FROM " + vTableName + " T )";
            }

            if (DBUtil.isMySql()) {
                starWithConn = "";
            }

            String curSql;
            if (accountIsBetween == 1) {
                if (isOneDimQuery != null && isOneDimQuery == 1) {
                    sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, compIdCon, kmStopCon, starWithConn);
                    log.info(sql);
                    kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
                    returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID AND Q.IID = A.ACC_SUB ";
                    curSql = "";
                    if (isForCur == 1) {
                        if (DBUtil.isMySql()) {
                            curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  ";
                        } else {
                            curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                        }

                        if (moneyType == -3) {
                            curSql = "SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                        }

                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID_MONEY_TYPE, accountIdSelectSql, curSql));
                    } else if (oneDimQueryIsSelectDimValue == 1) {
                        curSql = "SELECT DISTINCT " + moneyType + " AS MONEY1, " + moneyCol + " FROM " + vTableName + " A WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID_MONEY_TYPE, accountIdSelectSql, curSql));
                    } else {
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID, accountIdSelectSql));
                    }
                } else if (isSelectDim == 1) {
                    sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, compIdCon, kmStopCon, starWithConn);
                    log.info(sql);
                    kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
                    returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID AND Q.IID = A.ACC_SUB ";
                    curSql = "";
                    if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                        if (isForCur == 1) {
                            if (DBUtil.isMySql()) {
                                curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  ";
                            } else {
                                curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                            }

                            kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID_MONEY_TYPE, accountIdSelectSql, curSql));
                        } else {
                            curSql = "SELECT DISTINCT " + moneyType + " AS MONEY1, " + moneyCol + " FROM " + vTableName + " A WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK_ID= " + accbookid + compidCondition;
                            kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID_MONEY_TYPE, accountIdSelectSql, curSql));
                        }
                    } else {
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID, accountIdSelectSql));
                    }
                } else {
                    sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_ACCOUNT, itemCodeCon, compIdCon, kmStopCon, starWithConn, accountIdSelectSql);
                    log.info(sql);
                    returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID AND A.ACC_SUB = Y.KMID ";
                }
            } else if (isOneDimQuery != null && isOneDimQuery == 1) {
                sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, compIdCon, kmStopCon, starWithConn);
                log.info(sql);
                kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
                returnSql = " AND Q.IID = A.ACC_SUB ";
                if (isForCur == 1) {
                    curSql = AccComprehensiveQueryDaoConst.RETUEN_MONEY_TYPE_FOR_CUR;
                    if (moneyType == -3) {
                        curSql = " WITH KMACC AS (SELECT NULL ACCOUNT_ID, NULL IID, NULL COMPID, NULL ZDNAME,{0} AS MONEY1, {1} AS MONEY2  FROM DUAL )";
                    }

                    kmAndDimAndAccSelectSql.append(MessageFormat.format(curSql, staCur, moneyType));
                } else if (oneDimQueryIsSelectDimValue != null && oneDimQueryIsSelectDimValue == 1) {
                    curSql = " WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_MONEY_TYPE, moneyType, vTableName + " A ", curSql, moneyCol));
                }
            } else if (isSelectDim == 1) {
                sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, compIdCon, kmStopCon, starWithConn);
                log.info(sql);
                kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
                returnSql = " AND Q.IID = A.ACC_SUB ";
                if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                    if (isForCur == 1) {
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_MONEY_TYPE_FOR_CUR, staCur, moneyType));
                    } else {
                        curSql = " WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_MONEY_TYPE, moneyType, vTableName + " A ", curSql, moneyCol));
                    }
                }
            } else {
                sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF, itemCodeCon, compIdCon, kmStopCon, starWithConn);
                log.info(sql);
                returnSql = " AND A.ACC_SUB = Y.KMID ";
            }
        }

        kmAndAccJoinTable.append(" GT_ZW_WDBILLMX2 Y ,");
        return returnSql;
    }

    private String analyzeKmHaveValeNoOneDimDetail(Map<String, Object> param, StringBuffer kmAndAccJoinTable, StringBuffer kmAndDimAndAccSelectSql, String itemCodeCon, String showItemCodeCon, String starWithCon) {
        String returnSql = "";
        Integer accountIsBetween = ConvertUtil.toInteger(param.get("accountIsBetween"));
        Map<String, Object> params = new HashMap();
        String compIdCon = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        Integer isSelectDim = ConvertUtil.toInteger(param.get("isSelectDim"));
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer oneDimQueryIsSelectDimValue = ConvertUtil.toInteger(param.get("oneDimQueryIsSelectDimValue"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        int moneyType = ConvertUtil.toInt(param.get("moneyType"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        String oldCompid = ConvertUtil.toString(param.get("detailCompid"));
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
        String compidCondition = "  AND A.FINA_ORG = '" + oldCompid + "'";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String balTable = "ACC_BAL_SUM{1}_TOP";
        if (isBottomUnit) {
            balTable = "ACC_BAL_SUM{1}";
        }

        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_SUM{1}_TOP";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
        }

        String moneyCol = " FOR_CUR MONEY2";
        if (!StringUtils.equals("COLLECTIONDATA", dataOption)) {
            if ("CONTRADATA1".equals(dataOption)) {
                balTable = "OSET_BAL_DIM_SUM{1}_TOP";
            } else {
                balTable = "OSET_BAL_DIM_SUM{1}";
            }

            Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
            if (mxdwQuery != null && mxdwQuery == 1) {
                compidCondition = "  AND A.OSET_VOU_UNI = '" + oldCompid + "'";
                balTable = "OSET_BAL_DIM_SUM{1}";
                if ("MERGEDATA".equals(dataOption)) {
                    balTable = "ACC_BAL_SUM{1}_TOP";
                    compidCondition = "  AND A.FINA_ORG = '" + oldCompid + "'";
                }
            }
        }

        String vTableName = "";
        vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            vTableName = "(SELECT " + fileds + " FROM " + vTableName + " T )";
        }

        String accountIdSelectSql = ConvertUtil.toString(param.get("accountIdSelectSql"));
        String kmStopCon = "";
        params.put("TYEAR", accountYear);
        params.put("BOOKID", accbookid);
        String starWithConn = starWithCon;
        if (DBUtil.isMySql()) {
            starWithConn = "";
        }

        String s = "SELECT DISTINCT " + moneyType + " AS MONEY1, " + moneyCol + " FROM " + vTableName + " A WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
        String sql;
        String curSql;
        if (accountIsBetween == 1) {
            if (isOneDimQuery != null && isOneDimQuery == 1) {
                sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, "", kmStopCon, starWithConn);
                log.info(sql);
                log.info(sql);
                kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID AND Q.IID = A.ACC_SUB ";
                curSql = "";
                if (isForCur == 1) {
                    if (DBUtil.isMySql()) {
                        curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2 ";
                    } else {
                        curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                    }

                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_MONEY_TYPE, accountIdSelectSql, accountYear, accbookid, oldCompid, curSql));
                } else if (oneDimQueryIsSelectDimValue == 1) {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_MONEY_TYPE, accountIdSelectSql, accountYear, accbookid, oldCompid, s));
                } else {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT, accountIdSelectSql, accountYear, accbookid, oldCompid));
                }
            } else if (isSelectDim == 1) {
                sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, "", kmStopCon, starWithConn);
                log.info(sql);
                kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID AND Q.IID = A.ACC_SUB ";
                kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT, accountIdSelectSql, accountYear, accbookid, oldCompid));
            } else {
                sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_COMP_ACCOUNT, itemCodeCon, "", kmStopCon, starWithConn, accountIdSelectSql, oldCompid);
                log.info(sql);
                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID AND A.ACC_SUB = Y.KMID ";
            }
        } else if (isOneDimQuery != null && isOneDimQuery == 1) {
            sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, "", kmStopCon, starWithConn);
            log.info(sql);
            kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
            returnSql = " AND Q.IID = A.ACC_SUB ";
            curSql = "";
            if (isForCur == 1) {
                if (DBUtil.isMySql()) {
                    curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2 UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  ";
                } else {
                    curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                }

                kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_MONEY_TYPE, accountYear, accbookid, oldCompid, curSql));
            } else if (oneDimQueryIsSelectDimValue == 1) {
                kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_MONEY_TYPE, accountYear, accbookid, oldCompid, s));
            } else {
                kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP, accountYear, accbookid, oldCompid));
            }
        } else if (isSelectDim == 1) {
            sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, "", kmStopCon, starWithConn);
            log.info(sql);
            kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
            returnSql = " AND Q.IID = A.ACC_SUB ";
            kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP, accountYear, accbookid, oldCompid));
        } else {
            sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_COMP, itemCodeCon, "", kmStopCon, starWithConn, oldCompid);
            log.info(sql);
            returnSql = " AND A.ACC_SUB = Y.KMID ";
        }

        return returnSql;
    }

    private String analyzeKmHaveValeExport(Map<String, Object> param, StringBuffer kmAndAccJoinTable, StringBuffer kmAndDimAndAccSelectSql, String itemCodeCon, String showItemCodeCon, String starWithCon) {
        String returnSql = "";
        Integer accountIsBetween = ConvertUtil.toInteger(param.get("accountIsBetween"));
        Map<String, Object> params = new HashMap();
        String compIdCon = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        Integer isSelectDim = ConvertUtil.toInteger(param.get("isSelectDim"));
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer oneDimQueryIsSelectDimValue = ConvertUtil.toInteger(param.get("oneDimQueryIsSelectDimValue"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        int moneyType = ConvertUtil.toInt(param.get("moneyType"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        String compId = ConvertUtil.toString(param.get("unitControl"));
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        String compidCondition = "  AND A.FINA_ORG = '" + compId + "'";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String balTable = "ACC_BAL_SUM{1}_TOP";
        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_SUM{1}_TOP";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
        }

        String compid = ConvertUtil.toString(param.get("selectcompid"));
        String moneyCol = " FOR_CUR MONEY2";
        if (dataOption.contains("CONTRADATA")) {
            balTable = "OSET_BAL_CLCT{1}";
            compidCondition = "  AND A.OSET_VOU_UNI IN ('" + compid.replaceAll(",", "','") + "')";
            moneyCol = " FOR_CUR MONEY2 ";
        }

        String vTableName = "";
        vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            vTableName = "(SELECT " + fileds + " FROM " + vTableName + " T )";
        }

        String accountIdSelectSql = ConvertUtil.toString(param.get("accountIdSelectSql"));
        String kmStopCon = "";
        params.put("TYEAR", accountYear);
        params.put("BOOKID", accbookid);
        String s = "SELECT DISTINCT " + moneyType + " AS MONEY1, " + moneyCol + " FROM " + vTableName + " A WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
        String sql;
        String curSql;
        if (accountIsBetween == 1) {
            if (isOneDimQuery != null && isOneDimQuery == 1) {
                sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, "", kmStopCon, starWithCon);
                log.info(sql);
                kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID AND Q.IID = A.ACC_SUB ";
                curSql = "";
                if (isForCur == 1) {
                    curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_MONEY_TYPE_EXPORT, accountIdSelectSql, curSql));
                } else if (oneDimQueryIsSelectDimValue == 1) {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_MONEY_TYPE_EXPORT, accountIdSelectSql, s));
                } else {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_EXPORT, accountIdSelectSql));
                }
            } else if (isSelectDim == 1) {
                sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, "", kmStopCon, starWithCon);
                log.info(sql);
                kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID AND Q.IID = A.ACC_SUB ";
                kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_EXPORT, accountIdSelectSql));
            } else {
                sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_COMP_ACCOUNT_EXPORT, itemCodeCon, "", kmStopCon, starWithCon, accountIdSelectSql);
                log.info(sql);
                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID AND A.ACC_SUB = Y.KMID ";
            }
        } else if (isOneDimQuery != null && isOneDimQuery == 1) {
            sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, "", kmStopCon, starWithCon);
            log.info(sql);
            kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
            returnSql = " AND Q.IID = A.ACC_SUB ";
            curSql = "";
            if (isForCur == 1) {
                curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_MONEY_TYPE_EXPORT, curSql));
            } else if (oneDimQueryIsSelectDimValue == 1) {
                kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_MONEY_TYPE_EXPORT, s));
            } else {
                kmAndDimAndAccSelectSql.append(AccComprehensiveQueryDaoConst.RETURN_COMP_EXPORT);
            }
        } else if (isSelectDim == 1) {
            sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_FOR_DIM, itemCodeCon, "", kmStopCon, starWithCon);
            log.info(sql);
            kmAndAccJoinTable.append(" GT_KMSRCTAB Q ,");
            returnSql = " AND Q.IID = A.ACC_SUB ";
            kmAndDimAndAccSelectSql.append(AccComprehensiveQueryDaoConst.RETURN_COMP_EXPORT);
        } else {
            sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_LEAF_COMP_EXPORT, itemCodeCon, "", kmStopCon, starWithCon);
            log.info(sql);
            returnSql = " AND A.ACC_SUB = Y.KMID ";
        }

        return returnSql;
    }

    private String analyzeSelectKmNoVale(Map<String, Object> param, StringBuffer kmAndAccJoinTable, StringBuffer kmAndDimAndAccSelectSql) {
        String returnSql = "";
        Integer accountIsBetween = ConvertUtil.toInteger(param.get("accountIsBetween"));
        Map<String, Object> params = new HashMap();
        String compId = ConvertUtil.toString(param.get("unitControl"));
        String compIdCon = "AND FINA_ORG = '" + compId + "'";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        Integer isSelectDim = ConvertUtil.toInteger(param.get("isSelectDim"));
        params.put("TYEAR", accountYear);
        params.put("BOOKID", accbookid);
        String accountIdSelectSql = ConvertUtil.toString(param.get("accountIdSelectSql"));
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer oneDimQueryIsSelectDimValue = ConvertUtil.toInteger(param.get("oneDimQueryIsSelectDimValue"));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        
        String isBottLay = "";
        if (StringUtils.equals("13", ConvertUtil.toString(param.get("kmLevel")))) {
            if (DBUtil.isMySql()) {
                isBottLay = " AND S.IS_BOTT_LAY = 1 ";
            } else {
                isBottLay = " WHERE IS_BOTT_LAY = 1";
            }
        }

        String excuteSql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_KM_TREE, "", "", compIdCon, "", isBottLay);
        boolean hasAnalyze = ConvertUtil.toBoolean(param.get("hasAnalyze"));
        if (!hasAnalyze) {
            log.info(excuteSql);
        }

        if (mxdwQuery != null && mxdwQuery == 1) {
            kmAndAccJoinTable.append(" GT_ZW_WDBILLMX2 Y,");
            returnSql = this.analyzeNoKmHaveValeDetail(param, kmAndDimAndAccSelectSql);
        } else if (returnCount == 0 && ConvertUtil.toString(param.get("selectcompid")).contains(",")) {
            kmAndAccJoinTable.append(" GT_ZW_WDBILLMX2 Y,");
            returnSql = this.analyzeNoKmHaveValeExport(param, kmAndDimAndAccSelectSql);
        } else {
            int isForCur = ConvertUtil.toInt(param.get("isForCur"));
            int moneyType = ConvertUtil.toInt(param.get("moneyType"));
            int staCur = ConvertUtil.toInt(param.get("staCur"));
            String endAccountId = ConvertUtil.toString(param.get("endAccount"));
            boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
            String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
            String dataOption = ConvertUtil.toString(param.get("dataOption"));
            String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
            String balTable = "ACC_BAL_SUM{1}";
            String vTableName = "";
            if (!isBottomUnit) {
                balTable = "ACC_BAL_SUM{1}_TOP";
            }

            String fileds = null;
            if (StringUtils.isNotEmpty(selectPftCompId)) {
                balTable = "{0}ACC_PFT_BAL_SUM{1}";
                fileds = " T.PROF_CEN FINA_ORG, T.* ";
                if (!isBottomUnit) {
                    balTable = "{0}ACC_PFT_BAL_SUM{1}_TOP";
                }
            }

            String moneyCol = " FOR_CUR MONEY2";
            if (dataOption.contains("CONTRADATA")) {
                if ("CONTRADATA1".equals(dataOption)) {
                    balTable = "OSET_BAL_SUM{1}_TOP";
                } else {
                    balTable = "OSET_BAL_SUM{1}";
                }

                compidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
                moneyCol = " FOR_CUR MONEY2 ";
            }

            vTableName = MessageFormat.format(balTable, "", accountYear);
            if (StringUtils.isNotEmpty(selectPftCompId)) {
                vTableName = "(SELECT " + fileds + " FROM " + vTableName + " T )";
            }

            String s;
            if (accountIsBetween == 1) {
                s = "SELECT DISTINCT " + moneyType + " AS MONEY1, " + moneyCol + " FROM " + vTableName + " A WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
                String curSql;
                if (isOneDimQuery != null && isOneDimQuery == 1) {
                    curSql = "";
                    if (isForCur == 1) {
                        if (DBUtil.isMySql()) {
                            curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2   UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2   ";
                        } else {
                            curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                        }

                        if (moneyType == -3) {
                            curSql = "SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                        }

                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID_MONEY_TYPE, accountIdSelectSql, curSql));
                    } else if (oneDimQueryIsSelectDimValue == 1) {
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID_MONEY_TYPE, accountIdSelectSql, s));
                    } else {
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID, accountIdSelectSql));
                    }
                } else if (isSelectDim == 1) {
                    if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                        curSql = "";
                        if (isForCur == 1) {
                            if (DBUtil.isMySql()) {
                                curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2   UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2   ";
                            } else {
                                curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                            }

                            kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID_MONEY_TYPE, accountIdSelectSql, curSql));
                        } else {
                            kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID_MONEY_TYPE, accountIdSelectSql, s));
                        }
                    } else {
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_ACCOUNT_ID, accountIdSelectSql));
                    }
                } else {
                    curSql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_ACCOUNT_ID, accountIdSelectSql);
                    log.info(curSql);
                }

                kmAndAccJoinTable.append(" GT_ZW_WDBILLMX2 Y,");
                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID ";
            } else if (isSelectDim == 1) {
                kmAndAccJoinTable.append(" GT_ZW_WDBILLMX2 Y,");
                if (isOneDimQuery != null && isOneDimQuery == 1) {
                    if (isForCur == 1) {
                        s = AccComprehensiveQueryDaoConst.RETUEN_MONEY_TYPE_FOR_CUR;
                        if (moneyType == -3) {
                            s = " WITH KMACC AS (SELECT NULL ACCOUNT_ID, NULL IID, NULL COMPID, NULL ZDNAME,{0} AS MONEY1, {1} AS MONEY2  FROM DUAL )";
                        }

                        kmAndDimAndAccSelectSql.append(MessageFormat.format(s, staCur, moneyType));
                    } else if (oneDimQueryIsSelectDimValue == 1) {
                        s = " WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_MONEY_TYPE, moneyType, vTableName + " A ", s, moneyCol));
                    }
                } else if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                    if (isForCur == 1) {
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_MONEY_TYPE_FOR_CUR, staCur, moneyType));
                    } else {
                        s = " WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
                        kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETUEN_MONEY_TYPE, moneyType, vTableName + " A ", s, moneyCol));
                    }
                }
            }
        }

        return returnSql;
    }

    private String analyzeNoKmHaveValeDetail(Map<String, Object> param, StringBuffer kmAndDimAndAccSelectSql) {
        String returnSql = "";
        Integer accountIsBetween = ConvertUtil.toInteger(param.get("accountIsBetween"));
        Map<String, Object> params = new HashMap();
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        Integer isSelectDim = ConvertUtil.toInteger(param.get("isSelectDim"));
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer oneDimQueryIsSelectDimValue = ConvertUtil.toInteger(param.get("oneDimQueryIsSelectDimValue"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        int moneyType = ConvertUtil.toInt(param.get("moneyType"));
        String accountIdSelectSql = ConvertUtil.toString(param.get("accountIdSelectSql"));
        params.put("TYEAR", accountYear);
        params.put("BOOKID", accbookid);
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        String oldCompid = ConvertUtil.toString(param.get("detailCompid"));
        String compidCondition = "  AND A.FINA_ORG = '" + oldCompid + "'";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        String balTable = "ACC_BAL_SUM{1}_TOP";
        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_SUM{1}_TOP";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
        }

        String moneyCol = " FOR_CUR MONEY2";
        if (!StringUtils.equals("COLLECTIONDATA", dataOption)) {
            compidCondition = "  AND A.OSET_VOU_UNI = '" + oldCompid + "'";
            moneyCol = " FOR_CUR MONEY2 ";
            if ("CONTRADATA1".equals(dataOption)) {
                balTable = "OSET_BAL_SUM{1}_TOP";
            } else {
                balTable = "OSET_BAL_SUM{1}";
            }

            Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
            if (mxdwQuery != null && mxdwQuery == 1) {
                compidCondition = "  AND A.OSET_VOU_UNI = '" + oldCompid + "'";
                balTable = "OSET_BAL_SUM{1}";
            }
        }

        String vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            vTableName = "(SELECT " + fileds + " FROM " + vTableName + " T )";
        }

        String s = "SELECT DISTINCT " + moneyType + " AS MONEY1, " + moneyCol + " FROM " + vTableName + " A WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
        String curSql;
        if (accountIsBetween == 1) {
            if (isOneDimQuery != null && isOneDimQuery == 1) {
                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID  ";
                curSql = "";
                if (isForCur == 1) {
                    if (DBUtil.isMySql()) {
                        curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2   UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2   ";
                    } else {
                        curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                    }

                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_MONEY_TYPE, accountIdSelectSql, accountYear, accbookid, oldCompid, curSql));
                } else if (oneDimQueryIsSelectDimValue == 1) {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_MONEY_TYPE, accountIdSelectSql, accountYear, accbookid, oldCompid, s));
                } else {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT, accountIdSelectSql, accountYear, accbookid, oldCompid));
                }
            } else {
                if (isSelectDim == 1) {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT, accountIdSelectSql, accountYear, accbookid, oldCompid));
                } else {
                    curSql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_COMP_ACCOUNT, accountIdSelectSql, oldCompid);
                    log.debug(curSql);
                }

                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID  ";
            }
        } else {
            if (isOneDimQuery != null && isOneDimQuery == 1) {
                curSql = "";
                if (isForCur == 1) {
                    if (DBUtil.isMySql()) {
                        curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2   UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2   ";
                    } else {
                        curSql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                    }

                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_MONEY_TYPE, accountYear, accbookid, oldCompid, curSql));
                } else if (oneDimQueryIsSelectDimValue == 1) {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_MONEY_TYPE, accountYear, accbookid, oldCompid, s));
                } else {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP, accountYear, accbookid, oldCompid));
                }
            } else if (isSelectDim == 1) {
                kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP, accountYear, accbookid, oldCompid));
            } else {
                curSql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_COMP, accountYear, accbookid, oldCompid);
            }

            returnSql = "";
        }

        return returnSql;
    }

    private String analyzeNoKmHaveValeExport(Map<String, Object> param, StringBuffer kmAndDimAndAccSelectSql) {
        String returnSql = "";
        Integer accountIsBetween = ConvertUtil.toInteger(param.get("accountIsBetween"));
        Map<String, Object> params = new HashMap();
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        Integer isSelectDim = ConvertUtil.toInteger(param.get("isSelectDim"));
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer oneDimQueryIsSelectDimValue = ConvertUtil.toInteger(param.get("oneDimQueryIsSelectDimValue"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        int moneyType = ConvertUtil.toInt(param.get("moneyType"));
        String accountIdSelectSql = ConvertUtil.toString(param.get("accountIdSelectSql"));
        params.put("TYEAR", accountYear);
        params.put("BOOKID", accbookid);
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        String unitControl = ConvertUtil.toString(param.get("unitControl"));
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        String compidCondition = "  AND A.FINA_ORG = '" + unitControl + "'";
        String balTable = "ACC_BAL_SUM{1}_TOP";
        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_SUM{1}_TOP";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
        }

        String compid = ConvertUtil.toString(param.get("selectcompid"));
        String moneyCol = " FOR_CUR MONEY2";
        if (dataOption.contains("CONTRADATA")) {
            compidCondition = "  AND A.OSET_VOU_UNI IN ('" + compid.replaceAll(",", "','") + "')";
            balTable = "OSET_BAL_CLCT{1}";
            moneyCol = " FOR_CUR MONEY2 ";
        }

        String vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            vTableName = "(SELECT " + fileds + " FROM " + vTableName + " T )";
        }

        String s = "SELECT DISTINCT " + moneyType + " AS MONEY1, " + moneyCol + " FROM " + vTableName + " A WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition;
        String sql;
        if (accountIsBetween == 1) {
            if (isOneDimQuery != null && isOneDimQuery == 1) {
                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID  ";
                sql = "";
                if (isForCur == 1) {
                    sql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_MONEY_TYPE_EXPORT, accountIdSelectSql, sql));
                } else if (oneDimQueryIsSelectDimValue == 1) {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_MONEY_TYPE_EXPORT, accountIdSelectSql, s));
                } else {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_EXPORT, accountIdSelectSql));
                }
            } else {
                if (isSelectDim == 1) {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_ACCOUNT_EXPORT, accountIdSelectSql));
                } else {
                    sql = MessageFormat.format(AccComprehensiveQueryDaoConst.BUILD_COMP_ACCOUNT_EXPORT, accountIdSelectSql);
                }

                returnSql = " AND A.ACC_PERIOD = Y.ACCOUNT_ID  ";
            }
        } else {
            if (isOneDimQuery != null && isOneDimQuery == 1) {
                sql = "";
                if (isForCur == 1) {
                    sql = "SELECT 1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL UNION SELECT -1 AS MONEY1, " + moneyType + " AS MONEY2  FROM DUAL ";
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_MONEY_TYPE_EXPORT, sql));
                } else if (oneDimQueryIsSelectDimValue == 1) {
                    kmAndDimAndAccSelectSql.append(MessageFormat.format(AccComprehensiveQueryDaoConst.RETURN_COMP_MONEY_TYPE_EXPORT, s));
                } else {
                    kmAndDimAndAccSelectSql.append(AccComprehensiveQueryDaoConst.RETURN_COMP_EXPORT);
                }
            } else if (isSelectDim == 1) {
                kmAndDimAndAccSelectSql.append(AccComprehensiveQueryDaoConst.RETURN_COMP_EXPORT);
            } else {
                sql = AccComprehensiveQueryDaoConst.BUILD_COMP_EXPORT;
            }

            returnSql = "";
        }

        return returnSql;
    }

    private void analyzeSelectWd(Map<String, Object> param) {
        String queryModel = ConvertUtil.toString(param.get("queryModel"));
        if ("1".equals(queryModel)) {
            Integer fzmxQuery = ConvertUtil.toInteger(param.get("fzmxQuery"));
            Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
            if ((fzmxQuery == null || fzmxQuery != 1) && (mxdwQuery == null || mxdwQuery != 1)) {
                this.analyzeSelectWdByDimCls(param);
            } else {
                this.analyzeSelectWdByDim(param);
            }
        } else {
            this.analyzeSelectWdByDim(param);
        }

    }

    private void analyzeSelectWdByDim(Map<String, Object> param) {
        StringBuilder subjectCondition = new StringBuilder();
        StringBuilder dimAccComSub = new StringBuilder();
        List<Map<String, Object>> selectDims = new ArrayList();
        String mainType = "2";
        int isSelectSubjectDim = 0;
        Object selectWdObj = param.get("selectWd");
        if (selectWdObj != null) {
            List<Map<String, Object>> selectWd = (List)selectWdObj;
            if (!CollectionUtils.isEmpty(selectWd)) {
                String kmValue = "";
                mainType = ConvertUtil.toString(((Map)selectWd.get(0)).get("wdname"));
                Iterator var10 = selectWd.iterator();

                while(var10.hasNext()) {
                    Map<String, Object> map = (Map)var10.next();
                    String type = ConvertUtil.toString(map.get("type"));
                    if ("2".equals(type)) {
                        kmValue = ConvertUtil.toString(map.get("selvalue"));
                        param.put("kmitemcode", kmValue);
                        isSelectSubjectDim = 1;
                    } else if ("0".equals(type)) {
                        selectDims.add(map);
                    } else if ("1".equals(type)) {
                        selectDims.add(map);
                        if (map.get("wdname").equals(mainType)) {
                            param.put("flitemcode", map);
                        }
                    }
                }

                subjectCondition.append(this.analyzeSelectKm(param, kmValue));
                dimAccComSub.append(this.analyzeSelectDim(param, selectDims));
            } else {
                subjectCondition.append(this.analyzeSelectKm(param, ""));
            }
        }

        Integer isYwflCollectData = ConvertUtil.toInteger(param.get("isYwflCollectData"));
        if (isYwflCollectData != null && isYwflCollectData == 1) {
            mainType = "0";
        }

        param.put("subjectCondition", subjectCondition.toString());
        param.put("isSelectSubjectDim", Integer.valueOf(isSelectSubjectDim));
        param.put("dimAccComSub", dimAccComSub.toString());
    }

    private String analyzeSelectDim(Map<String, Object> param, List<Map<String, Object>> selectDims) {
        this.bulidDimCol(param);
        String retuStr = "";
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        if (!CollectionUtils.isEmpty(selectDims)) {
            if (isOneDimQuery != null && isOneDimQuery == 1) {
                String type = ConvertUtil.toString(((Map)selectDims.get(0)).get("type"));
                if ("0".equals(type)) {
                    retuStr = this.getGldxFilterOneDim(param, (Map)selectDims.get(0));
                } else {
                    retuStr = this.getYwflFilterOneDim(param, (Map)selectDims.get(0));
                }
            } else {
                retuStr = this.getDimFilterNoOneDim(param, selectDims);
            }

            param.put("decodeDimTypeId", ConvertUtil.toString(((Map)selectDims.get(0)).get("lxid")));
        } else {
            boolean isShowAllWd = ConvertUtil.toBoolean(param.get("isShowAllWd"));
            if (isShowAllWd) {
                List<Map<String, Object>> showAllDims = (List)param.get("showAllDims");
                if (!CollectionUtils.isEmpty(showAllDims)) {
                    Integer isShowAllWdHaveOrOneDim = ConvertUtil.toInteger(param.get("isShowAllWdHaveOrOneDim"));
                    Integer oneDimIsCls = ConvertUtil.toInteger(param.get("oneDimIsCls"));
                    if (isShowAllWdHaveOrOneDim == 1) {
                        if (oneDimIsCls == 1) {
                            retuStr = this.getYwflFilterOneDim(param, (Map)showAllDims.get(0));
                        } else {
                            retuStr = this.getGldxFilterOneDim(param, (Map)showAllDims.get(0));
                        }
                    } else if (isShowAllWdHaveOrOneDim == 2) {
                        StringBuilder wdCondition = new StringBuilder("");
                        String lxid = "";


                        for(int j = 0; j < showAllDims.size(); ++j) {
                            Map<String, Object> wdDetail = (Map)showAllDims.get(j);
                            lxid = ConvertUtil.toString(wdDetail.get("lxid"));
                            int wdType = ConvertUtil.toInt(wdDetail.get("type"));
                            if (j != 0) {
                                wdCondition.append(" UNION ");
                            }

                            wdCondition.append(" SELECT '");
                            wdCondition.append(lxid);
                            wdCondition.append("' DIMTYPEID,");
                            wdCondition.append(wdType);
                            if (DBUtil.isMySql()) {
                                wdCondition.append(" DIMCLS,0 DIMVALUE, '' DIMGROUP ");
                            } else {
                                wdCondition.append(" DIMCLS,0 DIMVALUE, '' DIMGROUP FROM DUAL");
                            }
                        }

                        retuStr = wdCondition.toString();
                    }
                }
            }
        }

        return retuStr;
    }

    private void analyzeSelectWdByDimCls(Map<String, Object> param) {
        this.bulidDimCol(param);
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
        if (isOneDimQuery != null && isOneDimQuery != 0) {
            this.analyzeByDimClsOneDim(param);
        } else if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
            this.analyzeByDimClsOneDim(param);
        } else {
            this.analyzeWdByDimClsNoOneDim(param);
        }

    }

    private void analyzeByDimClsOneDim(Map<String, Object> param) {
        StringBuilder subjectCondition = new StringBuilder("");
        StringBuilder wdCondition = new StringBuilder("");
        StringBuilder findDimValueSql = new StringBuilder("");
        Object selectWdObj = param.get("schemeSelectWd");
        boolean isFromAccBalSum = false;
        int isSelectSubjectDim = 0;
        int isSelectDimValue = 0;
        if (selectWdObj != null) {
            List<Map<String, Object>> selectWd = (List)selectWdObj;
            if (selectWd.size() > 0) {
                String lxid = "";
                Iterator var12 = selectWd.iterator();

                label37:
                while(true) {
                    while(true) {
                        if (!var12.hasNext()) {
                            break label37;
                        }

                        Map<String, Object> map = (Map)var12.next();
                        String type = ConvertUtil.toString(map.get("type"));
                        if ("2".equals(type)) {
                            String selvalue = ConvertUtil.toString(map.get("wdtype"));
                            param.put("kmitemcode", selvalue);
                            subjectCondition.append(this.analyzeSelectKm(param, selvalue));
                            isSelectSubjectDim = 1;
                        } else {
                            List<Map<String, Object>> wdDetails = (List)map.get("wdDetails");
                            if (!CollectionUtils.isEmpty(wdDetails)) {
                                for(int j = 0; j < wdDetails.size(); ++j) {
                                    Map<String, Object> wdDetail = (Map)wdDetails.get(j);
                                    lxid = ConvertUtil.toString(wdDetail.get("lxid"));
                                    int wdType = ConvertUtil.toInt(wdDetail.get("type"));
                                    if (j != 0) {
                                        findDimValueSql.append(" UNION ");
                                    }

                                    findDimValueSql.append(" SELECT '");
                                    findDimValueSql.append(lxid);
                                    findDimValueSql.append("' DIMTYPEID,");
                                    findDimValueSql.append(wdType);
                                    findDimValueSql.append(" DIMCLS, 0 DIMVALUE,''DIMGROUP");
                                }

                                wdCondition.append(findDimValueSql);
                            }
                        }
                    }
                }
            }
        }

        param.put("subjectCondition", subjectCondition.toString());
        param.put("dimAccComSub", wdCondition.toString());
        param.put("isFromAccBalSum", 0);
        param.put("isSelectSubjectDim", Integer.valueOf(isSelectSubjectDim));
        param.put("isSelectDimValue", Integer.valueOf(isSelectDimValue));
    }

    private void analyzeWdByDimClsNoOneDim(Map<String, Object> param) {
        StringBuilder subjectCondition = new StringBuilder("");
        StringBuffer returnCondition = new StringBuffer("");
        StringBuilder wdCondition = new StringBuilder("");
        Object selectWdObj = param.get("schemeSelectWd");
        boolean isFromAccBalSum = false;
        String decodeDimTypeId = "";
        int isSelectSubjectDim = 0;
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        int moneyType = ConvertUtil.toInt(param.get("moneyType"));
        if (selectWdObj != null) {
            List<Map<String, Object>> selectWd = (List)selectWdObj;
            if (selectWd.size() > 0) {
                boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
                String accountYear = ConvertUtil.toString(param.get("accountYear"));
                String endAccountId = ConvertUtil.toString(param.get("endAccount"));
                String compid = ConvertUtil.toString(param.get("selectcompid"));
                int returnCount = ConvertUtil.toInt(param.get("returnCount"));
                String rowNum = "";
                if (returnCount > 0) {
                    if (DBUtil.isMySql()) {
                        rowNum = " LIMIT " + 3 * returnCount;
                    } else {
                        rowNum = " AND ROWNUM < " + 3 * returnCount;
                    }
                }

                Long accbookid = (Long) (param.get("accbookid"));
                String dataTypeCondition = ConvertUtil.toString(param.get("dataTypeCondition"));
                String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
                String dateTypeCon = "";
                if (StringUtils.isNotEmpty(dataTypeCondition)) {
                    dateTypeCon = " AND " + dataTypeCondition;
                }

                String balTable = "ACC_BAL_DIM_ROW{1}";
                if (!isBottomUnit) {
                    balTable = "ACC_BAL_DIM_ROW{1}_TOP";
                }

                String vTableName = MessageFormat.format(balTable, "", accountYear);
                String lxid = "";
                int isSelectSubject = 0;
                int i = 0;
                StringBuffer whereCondition = new StringBuffer(" AND (");
                Iterator var29 = selectWd.iterator();

                while(true) {
                    String s;
                    List wdDetails;
                    String colToRowWdCol;
                    while(var29.hasNext()) {
                        Map<String, Object> map = (Map)var29.next();
                        s = ConvertUtil.toString(map.get("type"));
                        if ("2".equals(s)) {
                            colToRowWdCol = ConvertUtil.toString(map.get("wdtype"));
                            param.put("kmitemcode", colToRowWdCol);
                            subjectCondition.append(this.analyzeSelectKm(param, colToRowWdCol));
                            isSelectSubjectDim = 1;
                            if (param.get("isSelectSubject") != null) {
                                isSelectSubject = ConvertUtil.toInt(param.get("isSelectSubject"));
                            }
                        } else {
                            if (i == 0) {
                                wdCondition.append(" SELECT DISTINCT A.DIM_GROUP FROM ");
                                wdCondition.append(vTableName);
                                wdCondition.append(" A  ");
                                if (isSelectSubject == 1) {
                                    wdCondition.append(", GT_KMSRCTAB B");
                                }

                                wdCondition.append(" WHERE A.ACC_PERIOD = ");
                                wdCondition.append(endAccountId);
                                wdCondition.append(" AND A.ACC_BOOK = ");
                                wdCondition.append(accbookid);
                                wdCondition.append(" AND A.FINA_ORG = '");
                                wdCondition.append(compid);
                                wdCondition.append("'");
                                if (isSelectSubject == 1) {
                                    wdCondition.append(" AND B.IID = A.ACC_SUB ");
                                }

                                if (isForCur == 1) {
                                    wdCondition.append(" AND A.STA_CUR = -1 AND A.FOR_CUR =  ");
                                    wdCondition.append(moneyType);
                                }

                                wdCondition.append(dateTypeCon);
                                wdCondition.append(accoStatusContion);
                            } else {
                                wdCondition.append(" AND EXISTS (SELECT 1  FROM ACC_DIM_GROUP N1 ");
                                wdCondition.append(" WHERE N1.DIM_GROUP = A.DIM_GROUP ");
                            }

                            wdDetails = (List)map.get("wdDetails");
                            if (!CollectionUtils.isEmpty(wdDetails)) {
                                StringBuilder outWhere = new StringBuilder(" AND ");
                                StringBuilder inWhere = new StringBuilder("AND (");

                                for(int j = 0; j < wdDetails.size(); ++j) {
                                    Map<String, Object> wdDetail = (Map)wdDetails.get(j);
                                    lxid = ConvertUtil.toString(wdDetail.get("lxid"));
                                    int wdType = ConvertUtil.toInt(wdDetail.get("type"));
                                    if (i == 0) {
                                        decodeDimTypeId = lxid;
                                        outWhere.append("  A.DIM_TYPE_ID = '");
                                        outWhere.append(lxid);
                                        outWhere.append("' AND A.DIM_CLS = ");
                                        outWhere.append(wdType);
                                    } else {
                                        if (j != 0) {
                                            outWhere.append(" OR ");
                                            inWhere.append(" OR ");
                                        }

                                        inWhere.append(" ( N1.DIM_TYPE_ID = '");
                                        inWhere.append(lxid);
                                        inWhere.append("' AND N1.DIM_CLS = ");
                                        inWhere.append(wdType);
                                        inWhere.append(" )");
                                        whereCondition.append(" OR ");
                                    }

                                    whereCondition.append("( A.DIM_TYPE_ID = '");
                                    whereCondition.append(lxid);
                                    whereCondition.append("' AND A.DIM_CLS =");
                                    whereCondition.append(wdType);
                                    whereCondition.append(")");
                                }

                                if (i == 0) {
                                    wdCondition.append(outWhere);
                                } else {
                                    inWhere.append(")");
                                    wdCondition.append(inWhere);
                                    wdCondition.append(")");
                                }
                            }

                            ++i;
                        }
                    }

                    wdCondition.append(rowNum);
                    String excSql = "";
                    String countSql = "";
                    s = String.format(wdCondition.toString(), "").replaceAll("DISTINCT A.DIM_GROUP", "COUNT(*) COUNTNUM");
                    if (isSelectSubject == 1) {
                        excSql = "INSERT INTO GT_BILLID (SEQID)" + String.format(wdCondition.toString(), "");
                        countSql = s;
                    } else {
                        excSql = "INSERT INTO GT_BILLID (SEQID)" + String.format(wdCondition.toString(), "");
                        countSql = s;
                    }

                    if (returnCount > 0) {
                        wdDetails = new ArrayList();
                        int busCount = ConvertUtil.toInt(((Map)wdDetails.get(0)).get("countnum"));
                        if (busCount >= 3 * returnCount) {
                            param.put("isAllData", 0);
                        } else {
                            param.put("isAllData", 1);
                        }
                    }

                    colToRowWdCol = ConvertUtil.toString(param.get("colToRowWdCol"));
                    if (DBUtil.isMySql()) {
                        this.buildDimFilterNoOneDimCon(param, returnCondition, whereCondition);
                    } else {
                        returnCondition.append(" SELECT  NULL DIMTYPEID, NULL DIMCLS, ");
                        returnCondition.append(" NULL DIMVALUE, A.DIM_GROUP DIMGROUP ");
                        returnCondition.append(colToRowWdCol);
                        returnCondition.append(" FROM GT_BILLID B, ACC_DIM_GROUP A, ACC_OBJ_MER_REL F ");
                        returnCondition.append(" WHERE A.DIM_GROUP = B.SEQID AND A.DIM_VAL = F.OBJ_ITEM_ID(+)");
                        returnCondition.append(whereCondition);
                        returnCondition.append(")");
                        returnCondition.append(" GROUP BY A.DIM_GROUP");
                    }
                    break;
                }
            }
        }

        param.put("subjectCondition", subjectCondition.toString());
        param.put("dimAccComSub", returnCondition.toString());
        param.put("isFromAccBalSum", 0);
        param.put("decodeDimTypeId", decodeDimTypeId);
        param.put("isSelectSubjectDim", Integer.valueOf(isSelectSubjectDim));
    }

    private String getYwflFilterOneDim(Map<String, Object> param, Map<String, Object> wdObject) {
        StringBuilder wdCondition = new StringBuilder("");
        String selvalue = ConvertUtil.toString(wdObject.get("selvalue"));
        String lxid = ConvertUtil.toString(wdObject.get("lxid"));
        String unitControl = ConvertUtil.toString(param.get("unitControl"));
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String maintype = ConvertUtil.toString(param.get("mainType"));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        param.put("fllxid", lxid);
        int isSelectDimValue = 0;
        String countSql;
        List itemcodes;
        if (StringUtils.isNotEmpty(selvalue) && !"null".equals(selvalue) && StringUtils.isNotEmpty(lxid) && !"null".equals(lxid) && !lxid.equals(selvalue)) {
            int i;
            HashMap params;
            String itemCode;
            if (DBUtil.isMySql()) {
                wdCondition.append(" WITH RECURSIVE TEMP AS ");
                wdCondition.append(" (SELECT IID, ITEMCODE, PITEMCODE, 1 AS LVL FROM T_XTITEMSYW_EXT ");
                wdCondition.append(" WHERE COMPID ='");
                wdCondition.append(unitControl);
                wdCondition.append("' AND TYEAR = ");
                wdCondition.append(accountYear);
                if (!"1".equals(maintype) && mxdwQuery != null && mxdwQuery == 1) {
                    params = new HashMap();
                    params.put("TYEAR", accountYear);
                    params.put("COMPID", unitControl);
                    countSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FL_FIND_ITEMCODE, selvalue.replaceAll(",", "','"));
                    itemcodes = new ArrayList();
                    itemCode = "";
                    if (!CollectionUtils.isEmpty(itemcodes)) {
                        for(i = 0; i < itemcodes.size(); ++i) {
                            if (i > 0) {
                                itemCode = itemCode + ",";
                            }

                            itemCode = itemCode + ((Map)itemcodes.get(i)).get("itemcode");
                        }
                    }

                    wdCondition.append(" AND ITEMCODE IN ('");
                    wdCondition.append(itemCode.replaceAll(",", "','"));
                    wdCondition.append("') ");
                } else {
                    wdCondition.append(" AND ITEMCODE IN ('");
                    wdCondition.append(selvalue.replaceAll(",", "','"));
                    wdCondition.append("') ");
                }

                wdCondition.append(" UNION ALL ");
                wdCondition.append(" SELECT B.IID, B.ITEMCODE, B.PITEMCODE, A.LVL + 1 AS LVL ");
                wdCondition.append(" FROM TEMP A, T_XTITEMSYW_EXT B ");
                wdCondition.append(" WHERE B.COMPID ='");
                wdCondition.append(unitControl);
                wdCondition.append("' AND B.TYEAR = ");
                wdCondition.append(accountYear);
                wdCondition.append("  AND A.ITEMCODE = B.PITEMCODE)");
                wdCondition.append(" SELECT DISTINCT '");
                wdCondition.append(lxid);
                wdCondition.append("' AS DIMTYPEID,1 DIMCLS, IID AS DIMVALUE, '' DIMGROUP FROM TEMP");
            } else {
                wdCondition.append(" SELECT '");
                wdCondition.append(lxid);
                wdCondition.append("' DIMTYPEID,1 DIMCLS, IID AS DIMVALUE, NULL DIMGROUP FROM");
                wdCondition.append("(SELECT IID  FROM (SELECT ITEMCODE, IID, LEAF");
                wdCondition.append(" FROM T_XTITEMSYW_EXT WHERE COMPID ='");
                wdCondition.append(unitControl);
                wdCondition.append("' AND TYEAR = ");
                wdCondition.append(accountYear);
                wdCondition.append(" CONNECT BY SUBSTR(ITEMCODE, 1, LENGTH(TRIM(ITEMCODE)) - 4) = PRIOR ITEMCODE ");
                if (!"1".equals(maintype) && mxdwQuery != null && mxdwQuery == 1) {
                    params = new HashMap();
                    params.put("TYEAR", accountYear);
                    params.put("COMPID", unitControl);
                    countSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FL_FIND_ITEMCODE, selvalue.replaceAll(",", "','"));
                    itemcodes = new ArrayList();
                    wdCondition.append(" START WITH ITEMCODE IN ('");
                    itemCode = "";
                    if (!CollectionUtils.isEmpty(itemcodes)) {
                        for(i = 0; i < itemcodes.size(); ++i) {
                            if (i > 0) {
                                itemCode = itemCode + ",";
                            }

                            itemCode = itemCode + ((Map)itemcodes.get(i)).get("itemcode");
                        }
                    }

                    wdCondition.append(itemCode.replaceAll(",", "','"));
                } else {
                    wdCondition.append(" START WITH ITEMCODE IN ('");
                    wdCondition.append(selvalue.replaceAll(",", "','"));
                }

                wdCondition.append("'))  WHERE LEAF = 1  GROUP BY IID)");
            }

            isSelectDimValue = 1;
        } else if (returnCount != 0) {
            wdCondition.append(" SELECT '");
            wdCondition.append(lxid);
            wdCondition.append("' DIMTYPEID,1 DIMCLS,IID DIMVALUE, '' DIMGROUP FROM T_XTITEMSYW_EXT WHERE COMPID ='");
            wdCondition.append(unitControl);
            wdCondition.append("' AND TYEAR = ");
            wdCondition.append(accountYear);
            wdCondition.append(" AND ITEMCODE LIKE '");
            wdCondition.append(lxid);
            wdCondition.append("%' AND LEAF = 1 ");
            isSelectDimValue = 1;
            String limitCondition;
            if (DBUtil.isMySql()) {
                limitCondition = " LIMIT " + 3 * returnCount;
            } else {
                limitCondition = " FETCH FIRST " + 3 * returnCount + " ROWS ONLY";
            }

            countSql = "SELECT COUNT(*) COUNTNUM FROM T_XTITEMSYW_EXT WHERE COMPID ='" + unitControl + "' AND TYEAR = " + accountYear + " AND ITEMCODE LIKE '" + lxid + "' AND LEAF = 1  " + limitCondition;
            itemcodes = new ArrayList();
            int busCount = ConvertUtil.toInt(((Map)itemcodes.get(0)).get("countnum"));
            if (busCount >= 3 * returnCount) {
                param.put("isAllData", 0);
            } else {
                param.put("isAllData", 1);
            }
        } else {
            wdCondition.append(" SELECT '");
            wdCondition.append(lxid);
            if (DBUtil.isMySql()) {
                wdCondition.append("' DIMTYPEID,1 DIMCLS,0 DIMVALUE, '' DIMGROUP ");
            } else {
                wdCondition.append("' DIMTYPEID,1 DIMCLS,NULL DIMVALUE, NULL DIMGROUP FROM DUAL");
            }
        }

        param.put("isSelectDimValue", Integer.valueOf(isSelectDimValue));
        return wdCondition.toString();
    }

    private List<Map<String, Object>> buildSelectDims(List<Map<String, Object>> selectDims) {
        List<Map<String, Object>> newSelectDims = new ArrayList();
        List<Map<String, Object>> clsSelectDims = new ArrayList();
        List<Map<String, Object>> objectSelectDims = new ArrayList();
        List<Map<String, Object>> objectOrderSelectDims = new ArrayList();
        List<String> objectIds = new ArrayList();
        Map<String, Map<String, Object>> dimObjectMap = new HashMap();
        boolean isHave2021 = false;
        String selvalue = "";
        String attrtypeStr = "";
        String attrvalue = "";
        String lxid = "";
        Iterator var14 = selectDims.iterator();

        while(true) {
            while(true) {
                while(var14.hasNext()) {
                    Map<String, Object> dimMap = (Map)var14.next();
                    if (dimMap.containsKey("selvalue")) {
                        selvalue = ConvertUtil.toString(dimMap.get("selvalue"));
                    }

                    if (dimMap.containsKey("attrtype")) {
                        attrtypeStr = ConvertUtil.toString(dimMap.get("attrtype"));
                    }

                    if (dimMap.containsKey("attrvalue")) {
                        attrvalue = ConvertUtil.toString(dimMap.get("attrvalue"));
                    }

                    int dimCls = ConvertUtil.toInt(dimMap.get("type"));
                    lxid = ConvertUtil.toString(dimMap.get("lxid"));
                    if ("2021".equals(lxid)) {
                        isHave2021 = true;
                    }

                    if (dimCls == 0) {
                        if (!StringUtils.isNotEmpty(selvalue) && !StringUtils.isNotEmpty(attrtypeStr) && !StringUtils.isNotEmpty(attrvalue)) {
                            objectSelectDims.add(dimMap);
                            dimObjectMap.put(lxid, dimMap);
                            objectIds.add(lxid);
                        } else {
                            newSelectDims.add(dimMap);
                        }
                    } else if (StringUtils.isNotEmpty(selvalue)) {
                        newSelectDims.add(dimMap);
                    } else {
                        clsSelectDims.add(dimMap);
                    }
                }

                if (CollectionUtils.isEmpty(newSelectDims) && CollectionUtils.isEmpty(clsSelectDims)) {
                    Collections.sort(objectIds);
                    var14 = objectIds.iterator();

                    while(var14.hasNext()) {
                        String objectId = (String)var14.next();
                        if (!"2021".equals(objectId)) {
                            objectOrderSelectDims.add(dimObjectMap.get(objectId));
                        }
                    }

                    if (isHave2021) {
                        objectOrderSelectDims.add(dimObjectMap.get("2021"));
                    }

                    newSelectDims.addAll(objectOrderSelectDims);
                } else {
                    newSelectDims.addAll(clsSelectDims);
                    newSelectDims.addAll(objectSelectDims);
                }

                return newSelectDims;
            }
        }
    }

    private String getDimFilterNoOneDim(Map<String, Object> param, List<Map<String, Object>> selectDims) {
        StringBuilder wdCondition = new StringBuilder("");
        StringBuffer returnCondition = new StringBuffer("");
        if (!CollectionUtils.isEmpty(selectDims)) {
            Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
            if (mxdwQuery != null && mxdwQuery == 1) {
                return this.getDimFilterNoOneDimForDetail(param, selectDims);
            }

            boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
            String accountYear = ConvertUtil.toString(param.get("accountYear"));
            String endAccountId = ConvertUtil.toString(param.get("endAccount"));
            String compid = ConvertUtil.toString(param.get("selectcompid"));
            String unitControl = ConvertUtil.toString(param.get("unitControl"));
            int returnCount = ConvertUtil.toInt(param.get("returnCount"));
            int pcdReturnCount = 10000;
            Long accbookid = (Long)(param.get("accbookid"));
            int isForCur = ConvertUtil.toInt(param.get("isForCur"));
            int moneyType = ConvertUtil.toInt(param.get("moneyType"));
            String stacur = ConvertUtil.toString(param.get("staCur"));
            String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
            String dataOption = ConvertUtil.toString(param.get("dataOption"));
            String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
            String rowNum = "";
            if (returnCount > 0) {
                if (DBUtil.isMySql()) {
                    rowNum = " LIMIT " + 3 * returnCount;
                } else {
                    rowNum = " AND ROWNUM < " + 3 * returnCount;
                }

                pcdReturnCount = 3 * returnCount;
            }

            String dataTypeCondition = ConvertUtil.toString(param.get("dataTypeCondition"));
            String dateTypeCon = "";
            if (StringUtils.isNotEmpty(dataTypeCondition)) {
                (new StringBuilder()).append(" AND ").append(dataTypeCondition).toString();
            }

            String balTable = "ACC_BAL_DIM_ROW{1}";
            if (!isBottomUnit) {
                balTable = "ACC_BAL_DIM_ROW{1}_TOP";
            }

            String fileds = null;
            if (StringUtils.isNotEmpty(selectPftCompId)) {
                balTable = "{0}ACC_PFT_BAL_DIM_ROW{1}";
                fileds = " T.PROF_CEN FINA_ORG, T.* ";
                if (!isBottomUnit) {
                    balTable = "{0}ACC_PFT_BAL_DIM_ROW{1}_TOP";
                }
            }

            String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
            boolean isOset = false;
            if (dataOption.contains("CONTRADATA")) {
                isOset = true;
                compidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
                if ("CONTRADATA1".equals(dataOption)) {
                    balTable = "OSET_BAL_DIM_ROW{1}_TOP";
                    accoStatusContion = " AND A.DATA_TYPE = 1 ";
                } else {
                    balTable = "OSET_BAL_DIM_ROW{1}";
                    accoStatusContion = " AND A.DATA_TYPE = 0 ";
                }
            }

            String vTableName = MessageFormat.format(balTable, "", accountYear);
            if (StringUtils.isNotEmpty(selectPftCompId)) {
                String newFileds = fileds;
                if (isOset) {
                    newFileds = StringUtils.replace(fileds, "DIM_VAL", "DTL_DIM_ID");
                }

                vTableName = "(SELECT " + newFileds + " FROM " + vTableName + " T )";
            }

            StringBuffer whereCondition = new StringBuffer(" AND (");
            String dimCls = "";
            String wdname = "";
            String lxid = "";
            boolean firstDimIsSelectValueStaCur = false;
            int isSelectSubject = 0;
            if (param.get("isSelectSubject") != null) {
                isSelectSubject = ConvertUtil.toInt(param.get("isSelectSubject"));
            }

            List<Map<String, Object>> newSelectDims = this.buildSelectDims(selectDims);

            String selvalue;
            String attrtypeStr;
            String attrvalue;
            String nselvalue;
            for(int i = 0; i < newSelectDims.size(); ++i) {
                Map<String, Object> wdObject = (Map)newSelectDims.get(i);
                dimCls = ConvertUtil.toString(wdObject.get("type"));
                wdname = ConvertUtil.toString(wdObject.get("wdname"));
                lxid = ConvertUtil.toString(wdObject.get("lxid"));
                selvalue = "";
                attrtypeStr = "";
                attrvalue = "";
                if (wdObject.containsKey("selvalue")) {
                    selvalue = ConvertUtil.toString(wdObject.get("selvalue"));
                }

                if (wdObject.containsKey("attrtype")) {
                    attrtypeStr = ConvertUtil.toString(wdObject.get("attrtype"));
                }

                if (wdObject.containsKey("attrvalue")) {
                    attrvalue = ConvertUtil.toString(wdObject.get("attrvalue"));
                }

                if (i != 0) {
                    if (ConvertUtil.toBoolean(param.get("isCross"))) {
                        if (!StringUtils.isEmpty(selvalue)) {
                            wdCondition.append(" AND EXISTS (SELECT 1  FROM ACC_DIM_GROUP N1 ");
                        } else {
                            wdCondition.append(" AND NOT EXISTS (SELECT 1  FROM ACC_DIM_GROUP N1 ");
                        }
                    } else {
                        wdCondition.append(" AND EXISTS (SELECT 1  FROM ACC_DIM_GROUP N1 ");
                    }

                    wdCondition.append(" WHERE N1.DIM_GROUP = A.DIM_GROUP ");
                    wdCondition.append(" AND N1.DIM_CLS = ");
                    wdCondition.append(dimCls);
                    whereCondition.append(" OR ");
                } else {
                    wdCondition.append(" SELECT C.DIM_GROUP FROM (");
                    wdCondition.append(" SELECT %1$s DISTINCT A.DIM_GROUP FROM ");
                    wdCondition.append(vTableName);
                    wdCondition.append(" A ");
                    if (isSelectSubject == 1) {
                        wdCondition.append(", GT_KMSRCTAB B");
                    }

                    if (returnCount == 0 && compid.contains(",")) {
                        wdCondition.append(", HZ_COMPID_TREE G");
                    }

                    wdCondition.append(" %2$s ");
                    wdCondition.append(" WHERE A.ACC_PERIOD = ");
                    wdCondition.append(endAccountId);
                    if (returnCount == 0 && compid.contains(",")) {
                        wdCondition.append(" AND A.FINA_ORG = G.COMPID ");
                    } else {
                        wdCondition.append(compidCondition);
                    }

                    wdCondition.append(" AND A.ACC_BOOK = ");
                    wdCondition.append(accbookid);
                    wdCondition.append(" AND A.DIM_CLS = ");
                    wdCondition.append(dimCls);
                    if (isSelectSubject == 1) {
                        wdCondition.append(" AND B.IID = A.ACC_SUB ");
                    }

                    if (isForCur == 1) {
                        if (!isOset) {
                            if (moneyType != -3) {
                                wdCondition.append(" AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = ");
                                wdCondition.append(moneyType);
                            }
                        } else if (moneyType != -3) {
                            wdCondition.append(" AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = ");
                            wdCondition.append(moneyType);
                        }
                    }

                    wdCondition.append(accoStatusContion);
                }

                whereCondition.append("( A.DIM_TYPE_ID = '");
                whereCondition.append(lxid);
                whereCondition.append("' AND A.DIM_CLS =");
                whereCondition.append(dimCls);
                whereCondition.append(")");
                if (!StringUtils.isEmpty(selvalue)) {
                    if ("0".equals(dimCls)) {
                        nselvalue = this.dealGldxHbForWdCondition(selvalue, wdname);
                        if (i == 0) {
                            if (isForCur == 0) {
                                if (!isOset) {
                                    wdCondition.append(" AND A.STA_CUR = ");
                                    wdCondition.append(moneyType);
                                } else {
                                    wdCondition.append(" AND A.STA_CUR = ");
                                    wdCondition.append(moneyType);
                                }

                                firstDimIsSelectValueStaCur = true;
                            }

                            wdCondition.append(" AND A.DIM_TYPE_ID = '");
                            wdCondition.append(lxid);
                            wdCondition.append("'");
                            if (isOset) {
                                wdCondition.append(" AND A.DTL_DIM_ID IN ('");
                            } else {
                                wdCondition.append(" AND A.DIM_VAL IN ('");
                            }

                            wdCondition.append(nselvalue.replaceAll(",", "','"));
                            wdCondition.append("' )");
                        } else {
                            wdCondition.append(" AND N1.DIM_TYPE_ID = '");
                            wdCondition.append(lxid);
                            wdCondition.append("' AND N1.DIM_VAL IN ('");
                            wdCondition.append(nselvalue.replaceAll(",", "','"));
                            wdCondition.append("' )");
                            wdCondition.append(" ) ");
                        }
                    } else {
                        if (i == 0) {
                            if (isForCur == 0) {
                                if (!isOset) {
                                    wdCondition.append(" AND A.STA_CUR = ");
                                    wdCondition.append(moneyType);
                                } else {
                                    wdCondition.append(" AND A.STA_CUR = ");
                                    wdCondition.append(moneyType);
                                }

                                firstDimIsSelectValueStaCur = true;
                            }

                            wdCondition.append(" AND A.DIM_TYPE_ID = '");
                            wdCondition.append(lxid);
                            wdCondition.append("'");
                            if (isOset) {
                                wdCondition.append(" AND A.DTL_DIM_ID IN (");
                            } else {
                                wdCondition.append(" AND A.DIM_VAL IN (");
                            }
                        } else {
                            wdCondition.append(" AND N1.DIM_TYPE_ID = '");
                            wdCondition.append(lxid);
                            wdCondition.append("' AND N1.DIM_VAL IN (");
                        }

                        if (DBUtil.isMySql()) {
                            wdCondition.append(" WITH RECURSIVE TEMP AS ");
                            wdCondition.append(" (SELECT IID, ITEMCODE, PITEMCODE, 1 AS LVL FROM T_XTITEMSYW_EXT ");
                            wdCondition.append(" WHERE COMPID ='");
                            wdCondition.append(unitControl);
                            wdCondition.append("' AND TYEAR = ");
                            wdCondition.append(accountYear);
                            wdCondition.append(" AND ITEMCODE IN ('");
                            wdCondition.append(selvalue.replaceAll(",", "','"));
                            wdCondition.append("') ");
                            wdCondition.append(" UNION ALL ");
                            wdCondition.append(" SELECT B.IID, B.ITEMCODE, B.PITEMCODE, A.LVL + 1 AS LVL ");
                            wdCondition.append(" FROM TEMP A, T_XTITEMSYW_EXT B ");
                            wdCondition.append(" WHERE B.COMPID ='");
                            wdCondition.append(unitControl);
                            wdCondition.append("' AND B.TYEAR = ");
                            wdCondition.append(accountYear);
                            wdCondition.append("  AND A.ITEMCODE = B.PITEMCODE)");
                            wdCondition.append(" SELECT DISTINCT IID FROM TEMP )");
                        } else {
                            wdCondition.append("(SELECT IID FROM (SELECT IID, LEAF  FROM (SELECT ITEMCODE, IID, LEAF");
                            wdCondition.append(" FROM T_XTITEMSYW_EXT WHERE COMPID ='");
                            wdCondition.append(unitControl);
                            wdCondition.append("' AND TYEAR = ");
                            wdCondition.append(accountYear);
                            wdCondition.append(")");
                            wdCondition.append(" CONNECT BY SUBSTR(ITEMCODE, 1, LENGTH(TRIM(ITEMCODE)) - 4) = PRIOR ITEMCODE ");
                            wdCondition.append(" START WITH ITEMCODE IN ('");
                            wdCondition.append(selvalue.replaceAll(",", "','"));
                            wdCondition.append("'))  WHERE LEAF = 1  GROUP BY IID)");
                            wdCondition.append(" ) ");
                        }

                        if (i != 0) {
                            wdCondition.append(" ) ");
                        }
                    }
                } else if (!StringUtils.isNotEmpty(attrtypeStr)) {
                    if (i == 0) {
                        wdCondition.append(" AND A.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("'");
                    } else {
                        wdCondition.append(" AND N1.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("' ");
                        wdCondition.append(" ) ");
                    }
                } else if (!StringUtils.isNotEmpty(attrvalue)) {
                    if (i == 0) {
                        if (isForCur == 0) {
                            if (!isOset) {
                                wdCondition.append(" AND A.STA_CUR = ");
                                wdCondition.append(moneyType);
                            } else {
                                wdCondition.append(" AND A.STA_CUR = ");
                                wdCondition.append(moneyType);
                            }

                            firstDimIsSelectValueStaCur = true;
                        }

                        wdCondition.append(" AND A.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("'");
                    } else {
                        wdCondition.append(" AND N1.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("' ");
                        wdCondition.append(" ) ");
                    }
                } else {
                    if (i == 0) {
                        if (isForCur == 0) {
                            if (!isOset) {
                                wdCondition.append(" AND A.STA_CUR = ");
                                wdCondition.append(moneyType);
                            } else {
                                wdCondition.append(" AND A.STA_CUR = ");
                                wdCondition.append(moneyType);
                            }

                            firstDimIsSelectValueStaCur = true;
                        }

                        wdCondition.append(" AND A.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("'");
                        if (isOset) {
                            wdCondition.append(" AND A.DTL_DIM_ID IN (");
                        } else {
                            wdCondition.append(" AND A.DIM_VAL IN (");
                        }
                    } else {
                        wdCondition.append(" AND N1.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        if (isOset) {
                            wdCondition.append("' AND A.DTL_DIM_ID IN (");
                        } else {
                            wdCondition.append("' AND A.DIM_VAL IN (");
                        }
                    }


                    wdCondition.append(" SELECT DISTINCT DXID FROM DYCX_DXLIST ");
                    wdCondition.append(")");
                    if (i != 0) {
                        wdCondition.append(" ) ");
                    }
                }
            }

            wdCondition.append(rowNum);
            wdCondition.append(") C");
            List<String> replaceTabNameList = new ArrayList();
            if (wdCondition.indexOf("DYCX_DXLIST") != -1) {
                replaceTabNameList.add("DYCX_DXLIST");
            }

            String excSql = "";
            selvalue = "";
            attrtypeStr = " FOR_CUR ";
            if (firstDimIsSelectValueStaCur) {
                attrvalue = "ACC_BAL_SUM{1}";
                nselvalue = "";
                if (!isBottomUnit) {
                    attrvalue = "ACC_BAL_SUM{1}_TOP";
                }

                if (StringUtils.isNotEmpty(selectPftCompId)) {
                    attrvalue = "{0}ACC_PFT_BAL_SUM{1}";
                    fileds = " T.PROF_CEN FINA_ORG, T.* ";
                    if (!isBottomUnit) {
                        attrvalue = "{0}ACC_PFT_BAL_SUM{1}_TOP";
                    }
                }

                if (isOset) {
                    attrvalue = balTable;
                    attrtypeStr = " FOR_CUR FOR_CUR ";
                }

                nselvalue = MessageFormat.format(attrvalue, "", accountYear);
                String newFileds;
                if (StringUtils.isNotEmpty(selectPftCompId)) {
                    newFileds = fileds;
                    if (isOset) {
                        newFileds = StringUtils.replace(fileds, "DIM_VAL", "DTL_DIM_ID");
                    }

                    nselvalue = "(SELECT " + newFileds + " FROM " + nselvalue + " T ) ";
                }

                newFileds = ",(SELECT DISTINCT " + moneyType + " AS STA_CUR, " + attrtypeStr + "  FROM " + nselvalue + " A WHERE A.ACC_PERIOD = " + endAccountId + " AND A.ACC_BOOK= " + accbookid + compidCondition + accoStatusContion + " ) M";
                excSql = "INSERT INTO GT_BILLID (SEQID)" + String.format(wdCondition.toString(), "/*+ USE_NL(M,A) */", newFileds);
                selvalue = String.format(wdCondition.toString(), "/*+ USE_NL(M,A) */", newFileds).replaceAll("C\\.DIM_GROUP", "COUNT(*) COUNTNUM");
            } else {
                excSql = "INSERT INTO GT_BILLID (SEQID)" + String.format(wdCondition.toString(), "", "");
                selvalue = String.format(wdCondition.toString(), "", "").replaceAll("C\\.DIM_GROUP", "COUNT(*) COUNTNUM");
            }

            if (dataOption.contains("MERGEDATA")) {
                attrvalue = String.format(wdCondition.toString(), "", "");
                nselvalue = attrvalue.replace(vTableName, MessageFormat.format("OSET_BAL_DIM_ROW{1}_TOP", "", accountYear));
                nselvalue = nselvalue.replace("A.ENTRY_MARK", "A.DATA_TYPE");
                nselvalue = nselvalue.replace("A.FINA_ORG", "A.OSET_VOU_UNI");
                nselvalue = StringUtils.replace(nselvalue, "A.DIM_VAL", "A.DTL_DIM_ID");
                if (1 == isSelectSubject) {
                    nselvalue = nselvalue.replace("GT_KMSRCTAB", "GT_KMSRCTAB_COPY1");
                }

                excSql = "INSERT INTO GT_BILLID (SEQID)" + attrvalue + " union " + nselvalue;
                log.info(excSql);
                if (1 == isSelectSubject) {
                }
            } else {
                log.info(excSql);
            }

            if (returnCount > 0) {
                log.info(selvalue);
                int busCount = 0;
                if (busCount >= 3 * returnCount) {
                    param.put("isAllData", 0);
                } else {
                    param.put("isAllData", 1);
                }
            }

            attrvalue = ConvertUtil.toString(param.get("colToRowWdCol"));
            if (DBUtil.isMySql()) {
                this.buildDimFilterNoOneDimCon(param, returnCondition, whereCondition);
            } else {
                returnCondition.append(" SELECT  NULL DIMTYPEID, NULL DIMCLS, ");
                returnCondition.append(" NULL DIMVALUE, A.DIM_GROUP DIMGROUP ");
                returnCondition.append(attrvalue);
                returnCondition.append(" FROM GT_BILLID B, ACC_DIM_GROUP A, ACC_OBJ_MER_REL F");
                returnCondition.append(" WHERE A.DIM_GROUP = B.SEQID AND A.DIM_VAL = F.OBJ_ITEM_ID(+)");
                returnCondition.append(whereCondition);
                returnCondition.append(")");
                returnCondition.append(" GROUP BY A.DIM_GROUP ");
            }
        }

        return returnCondition.toString();
    }

    private String getDimFilterNoOneDimForDetail(Map<String, Object> param, List<Map<String, Object>> selectDims) {
        StringBuilder wdCondition = new StringBuilder("");
        StringBuffer returnCondition = new StringBuffer("");
        if (!CollectionUtils.isEmpty(selectDims)) {
            String accountYear = ConvertUtil.toString(param.get("accountYear"));
            String unitControl = ConvertUtil.toString(param.get("unitControl"));
            String maintype = ConvertUtil.toString(param.get("mainType"));
            StringBuffer whereCondition = new StringBuffer(" AND (");
            String dimCls = "";
            String wdname = "";
            String lxid = "";
            List<Map<String, Object>> newSelectDims = this.buildSelectDims(selectDims);

            for(int i = 0; i < newSelectDims.size(); ++i) {
                Map<String, Object> wdObject = (Map)newSelectDims.get(i);
                dimCls = ConvertUtil.toString(wdObject.get("type"));
                wdname = ConvertUtil.toString(wdObject.get("wdname"));
                lxid = ConvertUtil.toString(wdObject.get("lxid"));
                String selvalue = "";
                if (wdObject.containsKey("selvalue")) {
                    selvalue = ConvertUtil.toString(wdObject.get("selvalue"));
                }

                if (i != 0) {
                    whereCondition.append(" OR ");
                }

                whereCondition.append("( A.DIM_TYPE_ID = '");
                whereCondition.append(lxid);
                whereCondition.append("' AND A.DIM_CLS =");
                whereCondition.append(dimCls);
                whereCondition.append(")");
                if (StringUtils.isEmpty(selvalue)) {
                    if (i == 0) {
                        wdCondition.append(" INSERT INTO GT_BILLID (SEQID) ");
                        wdCondition.append(" SELECT DISTINCT A.DIM_GROUP FROM ACC_DIM_GROUP A ");
                        wdCondition.append(" WHERE  ");
                        wdCondition.append(" NOT EXISTS (SELECT 1  FROM ACC_DIM_GROUP N1 ");
                        wdCondition.append(" WHERE N1.DIM_GROUP = A.DIM_GROUP ");
                        wdCondition.append(" AND N1.DIM_CLS = ");
                        wdCondition.append(dimCls);
                        wdCondition.append(" AND N1.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("')");
                    } else {
                        wdCondition.append(" AND NOT EXISTS (SELECT 1  FROM ACC_DIM_GROUP N1 ");
                        wdCondition.append(" WHERE N1.DIM_GROUP = A.DIM_GROUP ");
                        wdCondition.append(" AND N1.DIM_CLS = ");
                        wdCondition.append(dimCls);
                        wdCondition.append(" AND N1.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("')");
                    }
                } else if ("0".equals(dimCls)) {
                    String nselvalue = this.dealGldxHbForWdCondition(selvalue, wdname);
                    if (i == 0) {
                        wdCondition.append(" INSERT INTO GT_BILLID (SEQID) ");
                        wdCondition.append(" SELECT DISTINCT A.DIM_GROUP FROM ACC_DIM_GROUP A ");
                        wdCondition.append(" WHERE  ");
                        wdCondition.append(" A.DIM_CLS = ");
                        wdCondition.append(dimCls);
                        wdCondition.append(" AND A.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("'");
                        wdCondition.append(" AND A.DIM_VAL IN ('");
                        wdCondition.append(nselvalue.replaceAll(",", "','"));
                        wdCondition.append("' )");
                    } else {
                        wdCondition.append(" AND EXISTS (SELECT 1  FROM ACC_DIM_GROUP N1 ");
                        wdCondition.append(" WHERE N1.DIM_GROUP = A.DIM_GROUP ");
                        wdCondition.append(" AND N1.DIM_CLS = ");
                        wdCondition.append(dimCls);
                        wdCondition.append(" AND N1.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("' AND N1.DIM_VAL IN ('");
                        wdCondition.append(nselvalue.replaceAll(",", "','"));
                        wdCondition.append("' )");
                        wdCondition.append(" ) ");
                    }
                } else {
                    if (i == 0) {
                        wdCondition.append(" INSERT INTO GT_BILLID (SEQID) ");
                        wdCondition.append(" SELECT DISTINCT A.DIM_GROUP FROM ACC_DIM_GROUP A ");
                        wdCondition.append(" WHERE  ");
                        wdCondition.append(" A.DIM_CLS = ");
                        wdCondition.append(dimCls);
                        wdCondition.append(" AND A.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("'");
                        wdCondition.append(" AND A.DIM_VAL IN (");
                    } else {
                        wdCondition.append(" AND EXISTS (SELECT 1  FROM ACC_DIM_GROUP N1 ");
                        wdCondition.append(" WHERE N1.DIM_GROUP = A.DIM_GROUP ");
                        wdCondition.append(" AND N1.DIM_CLS = ");
                        wdCondition.append(dimCls);
                        wdCondition.append(" AND N1.DIM_TYPE_ID = '");
                        wdCondition.append(lxid);
                        wdCondition.append("' AND N1.DIM_VAL IN (");
                    }

                    if ("1".equals(maintype) && i == 0) {
                        wdCondition.append("SELECT IID FROM ");
                        wdCondition.append(" T_XTITEMSYW_EXT WHERE COMPID ='");
                        wdCondition.append(unitControl);
                        wdCondition.append("' AND TYEAR = ");
                        wdCondition.append(accountYear);
                        wdCondition.append(" AND ITEMCODE IN ('");
                        wdCondition.append(selvalue.replaceAll(",", "','"));
                        wdCondition.append("') AND LEAF = 1  GROUP BY IID) ");
                    } else {
                        wdCondition.append("'");
                        wdCondition.append(selvalue.replaceAll(",", "','"));
                        wdCondition.append("') ");
                    }

                    if (i != 0) {
                        wdCondition.append(") ");
                    }
                }
            }
            log.info(whereCondition.toString());
            String colToRowWdCol = ConvertUtil.toString(param.get("colToRowWdCol"));
            if (DBUtil.isMySql()) {
                this.buildDimFilterNoOneDimCon(param, returnCondition, whereCondition);
            } else {
                returnCondition.append(" SELECT  '' DIMTYPEID, 0 DIMCLS, ");
                returnCondition.append(" 0 DIMVALUE, A.DIM_GROUP DIMGROUP ");
                returnCondition.append(colToRowWdCol);
                returnCondition.append(" FROM GT_BILLID B, ACC_DIM_GROUP A, ACC_OBJ_MER_REL F ");
                returnCondition.append(" WHERE A.DIM_GROUP = B.SEQID AND A.DIM_VAL = F.OBJ_ITEM_ID(+)");
                returnCondition.append(whereCondition);
                returnCondition.append(")");
                returnCondition.append(" GROUP BY A.DIM_GROUP ");
            }
        }

        return returnCondition.toString();
    }

    private void buildDimFilterNoOneDimCon(Map<String, Object> param, StringBuffer returnCondition, StringBuffer whereCondition) {


        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        String colToRowWdCol = ConvertUtil.toString(param.get("colToRowWdCol"));
        String insetDimSql = "INSERT INTO GT_ZW_WDBILLMX2_QT (DXLXID,TYPEBZ,GLDXID,KMCAPTION " + wdCol + ") SELECT  '' DIMTYPEID, 0 DIMCLS,  0 DIMVALUE, A.DIM_GROUP DIMGROUP " + colToRowWdCol + " FROM GT_BILLID B, ACC_DIM_GROUP A  WHERE A.DIM_GROUP = B.SEQID " + whereCondition + ") GROUP BY A.DIM_GROUP ";
        log.info(insetDimSql);
        String[] wdCols = wdCol.split(",");
        StringBuilder leftJoinTable = new StringBuilder("");
        StringBuilder selectCol = new StringBuilder("");
        int i = 0;
        String[] var11 = wdCols;
        int var12 = wdCols.length;

        for(int var13 = 0; var13 < var12; ++var13) {
            String wd = var11[var13];
            if (StringUtils.isNotEmpty(wd)) {
                leftJoinTable.append(" LEFT JOIN ACC_OBJ_MER_REL F");
                leftJoinTable.append(i);
                leftJoinTable.append(" ON A.");
                leftJoinTable.append(wd);
                leftJoinTable.append(" = F");
                leftJoinTable.append(i);
                leftJoinTable.append(".OBJ_ITEM_ID ");
                selectCol.append(", COALESCE(F");
                selectCol.append(i);
                selectCol.append(".OBJ_ID1,A.");
                selectCol.append(wd);
                selectCol.append(")");
            }

            ++i;
        }

        String insetDimSql1 = "INSERT INTO GT_ZW_WDBILLMX2_QT1 (DXLXID,TYPEBZ,GLDXID,KMCAPTION " + wdCol + ")SELECT DXLXID,TYPEBZ,GLDXID,KMCAPTION " + selectCol.toString() + " FROM GT_ZW_WDBILLMX2_QT A " + leftJoinTable.toString();
        log.info(insetDimSql1);
        returnCondition.append(" SELECT C.DXLXID DIMTYPEID,C.TYPEBZ DIMCLS,C.GLDXID DIMVALUE,C.KMCAPTION DIMGROUP ");
        returnCondition.append(wdCol);
        returnCondition.append(" FROM GT_ZW_WDBILLMX2_QT1 C");
    }

    private void batchInsertGldxDimValueList(String dimValue, Map<String, Object> param) {
        String sql = "INSERT INTO GT_ZW_WDBILLMX (KMCAPTION) VALUES (?)";
        boolean hasAnalyze = ConvertUtil.toBoolean(param.get("hasAnalyze"));
        if (!hasAnalyze) {
        } else {
        }

        if (StringUtils.isNotEmpty(dimValue)) {
            List<Object[]> params = (List)Arrays.stream(dimValue.split(",")).map((id) -> {
                return new Object[]{id};
            }).collect(Collectors.toList());
            log.info(sql);
        }

    }

    private String getGldxFilterOneDim(Map<String, Object> param, Map<String, Object> wdObject) {
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        boolean isMxdwQuery = mxdwQuery != null && mxdwQuery == 1;
        if (dataOption.contains("MERGEDATA") && !isMxdwQuery) {
            param.put("dataOption", "CONTRADATA1");
            param.put("getGldxFilterOneDimForMerge", this.getGldxFilterOneDim(param, wdObject));
            param.put("dataOption", "MERGEDATA");
        }

        StringBuilder wdCondition = new StringBuilder("");
        String wdname = ConvertUtil.toString(wdObject.get("wdname"));
        String lxid = ConvertUtil.toString(wdObject.get("lxid"));
        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        int pcdReturnCount = 3 * returnCount;
        String selvalue = "";
        String attrtypeStr = "";
        String attrvalue = "";
        if (wdObject.containsKey("selvalue")) {
            selvalue = ConvertUtil.toString(wdObject.get("selvalue"));
        }

        if (wdObject.containsKey("attrtype")) {
            attrtypeStr = ConvertUtil.toString(wdObject.get("attrtype"));
        }

        if (wdObject.containsKey("attrvalue")) {
            attrvalue = ConvertUtil.toString(wdObject.get("attrvalue"));
        }

        int isSelectDimValue = 0;
        if (!StringUtils.isEmpty(selvalue)) {
            this.batchInsertGldxDimValueList(selvalue, param);
            String nselvalue = this.dealGldxHbForWdCondition(selvalue, wdname);
            if (StringUtils.isNotEmpty(nselvalue)) {
                wdCondition.append(" SELECT '");
                wdCondition.append(lxid);
                wdCondition.append("' DIMTYPEID,0 DIMCLS,'' DIMGROUP,  KMCAPTION DIMVALUE FROM GT_ZW_WDBILLMX ");
                isSelectDimValue = 1;
            }
        } else {
            int isForCur;
            int moneyType;
            if (returnCount != 0) {
                boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
                Long accbookid = (Long)(param.get("accbookid"));
                String accountYear = ConvertUtil.toString(param.get("accountYear"));
                String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
                Integer isSelectSubject = ConvertUtil.toInteger(param.get("isSelectSubject"));
                String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
                String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
                isForCur = ConvertUtil.toInt(param.get("isForCur"));
                moneyType = ConvertUtil.toInt(param.get("moneyType"));
                String stacur = ConvertUtil.toString(param.get("staCur"));
                String endAccountId = ConvertUtil.toString(param.get("endAccount"));
                String balTable = "ACC_BAL_DIM_ROW{1}";
                String vTableName = "";
                if (!isBottomUnit) {
                    balTable = "ACC_BAL_DIM_ROW{1}_TOP";
                }

                String fileds = null;
                if (StringUtils.isNotEmpty(selectPftCompId)) {
                    balTable = "{0}ACC_PFT_BAL_DIM_ROW{1}";
                    fileds = " T.PROF_CEN FINA_ORG, T.* ";
                    if (!isBottomUnit) {
                        balTable = "{0}ACC_PFT_BAL_DIM_ROW{1}_TOP";
                    }
                }

                boolean isOset = false;
                if (dataOption.contains("CONTRADATA")) {
                    isOset = true;
                    compidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
                    if ("CONTRADATA1".equals(dataOption)) {
                        balTable = "OSET_BAL_DIM_ROW{1}_TOP";
                        accoStatusContion = " AND A.DATA_TYPE = 1 ";
                    } else {
                        balTable = "OSET_BAL_DIM_ROW{1}";
                        accoStatusContion = " AND A.DATA_TYPE = 0 ";
                    }
                }

                vTableName = MessageFormat.format(balTable, "", accountYear);
                if (StringUtils.isNotEmpty(selectPftCompId)) {
                    vTableName = "(SELECT " + fileds + " FROM " + vTableName + " T )";
                }

                String countSql = "";
                if (isSelectSubject != null && isSelectSubject == 1) {
                    countSql = "SELECT COUNT(*) COUNTNUM FROM " + vTableName + " A,(SELECT Y.DIMTYPEID,Y.DIMCLS,X.IID FROM GT_KMSRCTAB X,(SELECT '" + lxid + "' DIMTYPEID, 0 DIMCLS FROM DUAL) Y) B WHERE A.ACC_SUB = B.IID AND A.DIM_TYPE_ID = B.DIMTYPEID  AND A.DIM_CLS = B.DIMCLS AND A.ACC_PERIOD =" + endAccountId + " " + compidCondition + " " + accoStatusContion;
                    wdCondition.append(" SELECT DISTINCT DIMTYPEID,DIMCLS,DIMVALUE,DIMGROUP FROM (");
                    wdCondition.append(" SELECT  '");
                    wdCondition.append(lxid);
                    wdCondition.append("' DIMTYPEID,0 DIMCLS");
                    if (isOset) {
                        wdCondition.append(",A.DTL_DIM_ID AS DIMVALUE");
                    } else {
                        wdCondition.append(",A.DIM_VAL AS DIMVALUE");
                    }

                    wdCondition.append(",'' DIMGROUP FROM ");
                    wdCondition.append(vTableName);
                    wdCondition.append(" A,(SELECT Y.DIMTYPEID, Y.DIMCLS, X.IID FROM GT_KMSRCTAB X, (SELECT '");
                    wdCondition.append(lxid);
                    wdCondition.append("' DIMTYPEID, 0 DIMCLS FROM DUAL) Y) B ");
                    wdCondition.append(" WHERE A.ACC_SUB = B.IID ");
                    wdCondition.append("  AND A.DIM_TYPE_ID = B.DIMTYPEID  AND A.DIM_CLS = B.DIMCLS ");
                    wdCondition.append(" AND A.ACC_BOOK = ");
                    wdCondition.append(accbookid);
                    wdCondition.append(" AND A.ACC_PERIOD = ");
                    wdCondition.append(endAccountId);
                    wdCondition.append(compidCondition);
                    wdCondition.append(accoStatusContion);
                    if (isForCur == 1) {
                        if (!isOset) {
                            if (moneyType != -3) {
                                countSql = countSql + " AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = " + moneyType;
                                wdCondition.append(" AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = ");
                                wdCondition.append(moneyType);
                            }
                        } else if (moneyType != -3) {
                            countSql = countSql + " AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = " + moneyType;
                            wdCondition.append(" AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = ");
                            wdCondition.append(moneyType);
                        }
                    } else if (!isOset) {
                        if (moneyType != -3) {
                            countSql = countSql + " AND A.STA_CUR = " + moneyType;
                            wdCondition.append("AND A.STA_CUR = ");
                            wdCondition.append(moneyType);
                        }
                    } else if (moneyType != -3) {
                        countSql = countSql + " AND A.STA_CUR = " + moneyType;
                        wdCondition.append("AND A.STA_CUR = ");
                        wdCondition.append(moneyType);
                    }

                    if (DBUtil.isMySql()) {
                        countSql = countSql + " LIMIT " + 3 * returnCount;
                    } else {
                        countSql = countSql + " AND ROWNUM <= " + 3 * returnCount;
                    }

                    wdCondition.append(" )C");
                } else {
                    countSql = "SELECT COUNT(*) COUNTNUM FROM " + vTableName + " A WHERE  A.DIM_TYPE_ID ='" + lxid + "' AND A.DIM_CLS = 0 AND A.ACC_PERIOD =" + endAccountId + " " + compidCondition + " " + accoStatusContion;
                    wdCondition.append(" SELECT DISTINCT DIMTYPEID,DIMCLS,DIMVALUE,DIMGROUP FROM (");
                    wdCondition.append(" SELECT '");
                    wdCondition.append(lxid);
                    wdCondition.append("' DIMTYPEID,0 DIMCLS");
                    if (isOset) {
                        wdCondition.append(",A.DTL_DIM_ID AS DIMVALUE");
                    } else {
                        wdCondition.append(",A.DIM_VAL AS DIMVALUE");
                    }

                    wdCondition.append(", '' DIMGROUP FROM ");
                    wdCondition.append(vTableName);
                    wdCondition.append(" A WHERE A.DIM_TYPE_ID = '");
                    wdCondition.append(lxid);
                    wdCondition.append("' AND A.DIM_CLS = 0 AND A.ACC_PERIOD = ");
                    wdCondition.append(endAccountId);
                    wdCondition.append(" AND A.ACC_BOOK = ");
                    wdCondition.append(accbookid);
                    wdCondition.append(compidCondition);
                    wdCondition.append(accoStatusContion);
                    if (isForCur == 1) {
                        if (!isOset) {
                            if (moneyType != -3) {
                                countSql = countSql + " AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = " + moneyType;
                                wdCondition.append(" AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = ");
                                wdCondition.append(moneyType);
                            }
                        } else if (moneyType != -3) {
                            countSql = countSql + " AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = " + moneyType;
                            wdCondition.append(" AND A.STA_CUR = " + stacur + " AND A.FOR_CUR = ");
                            wdCondition.append(moneyType);
                        }
                    } else if (!isOset) {
                        if (moneyType != -3) {
                            countSql = countSql + " AND A.STA_CUR = " + moneyType;
                            wdCondition.append("AND A.STA_CUR = ");
                            wdCondition.append(moneyType);
                        }
                    } else if (moneyType != -3) {
                        countSql = countSql + " AND A.STA_CUR = " + moneyType;
                        wdCondition.append("AND A.STA_CUR = ");
                        wdCondition.append(moneyType);
                    }

                    if (DBUtil.isMySql()) {
                        countSql = countSql + " LIMIT " + 3 * returnCount;
                    } else {
                        countSql = countSql + " AND ROWNUM <= " + 3 * returnCount;
                    }

                    wdCondition.append(" )C");
                }

                isSelectDimValue = 1;
                log.info(countSql);
                int busCount = 0;
                if (busCount >= 3 * returnCount) {
                    param.put("isAllData", 0);
                } else {
                    param.put("isAllData", 1);
                }
            } else {
                wdCondition.append(" SELECT '");
                wdCondition.append(lxid);
                if (DBUtil.isMySql()) {
                    wdCondition.append("' DIMTYPEID,0 DIMCLS,0 DIMVALUE, '' DIMGROUP ");
                } else {
                    wdCondition.append("' DIMTYPEID,0 DIMCLS,NULL DIMVALUE, NULL DIMGROUP FROM DUAL");
                }
            }
        }

        param.put("isSelectDimValue", Integer.valueOf(isSelectDimValue));
        return wdCondition.toString();
    }

    private void analyzeMoneyType(Map<String, Object> param) {
        String moneyTypeOption = "";
        String osetMoneyTypeOption = "";
        int isForCur = 0;
        int moneyType = 1;
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer oneDimQueryIsSelectDimValue = ConvertUtil.toInteger(param.get("oneDimQueryIsSelectDimValue"));
        Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        AccBookBO accBookBO = new AccBookBO();
        accBookBO.setStaCur(1);
        param.put("staCur", accBookBO.getStaCur());
        if (isOneDimQuery != null && isOneDimQuery == 1) {
            if (moneyType != ConvertUtil.toInt(accBookBO.getStaCur())) {
                moneyTypeOption = " AND  A.STA_CUR = Y.MONEY1 AND A.FOR_CUR = Y.MONEY2 ";
                osetMoneyTypeOption = " AND  A.STA_CUR = Y.MONEY1 AND A.FOR_CUR = Y.MONEY2 ";
                isForCur = 1;
            } else if (oneDimQueryIsSelectDimValue == 1) {
                moneyTypeOption = " AND  A.STA_CUR = Y.MONEY1 AND A.FOR_CUR = Y.MONEY2 ";
                osetMoneyTypeOption = " AND  A.STA_CUR = Y.MONEY1 AND A.FOR_CUR = Y.MONEY2 ";
            } else {
                moneyTypeOption = " AND  A.STA_CUR = " + moneyType;
                osetMoneyTypeOption = " AND  A.STA_CUR = " + moneyType;
            }
        } else if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1 && (mxdwQuery == null || mxdwQuery == 0)) {
            if (moneyType != ConvertUtil.toInt(accBookBO.getStaCur())) {
                isForCur = 1;
            }

            moneyTypeOption = " AND  A.STA_CUR = Y.MONEY1 AND A.FOR_CUR = Y.MONEY2 ";
            osetMoneyTypeOption = " AND  A.STA_CUR = Y.MONEY1 AND A.FOR_CUR = Y.MONEY2 ";
        } else if (moneyType == ConvertUtil.toInt(accBookBO.getStaCur())) {
            moneyTypeOption = " AND  A.STA_CUR = " + moneyType;
            osetMoneyTypeOption = " AND  A.STA_CUR = " + moneyType;
        } else {
            moneyTypeOption = " AND  A.FOR_CUR = " + moneyType;
            osetMoneyTypeOption = " AND  A.FOR_CUR = " + moneyType;
            isForCur = 1;
        }

        if (moneyType == -3) {
            moneyTypeOption = "";
        }

        param.put("moneyTypeCondition", moneyTypeOption);
        param.put("osetMoneyTypeOption", osetMoneyTypeOption);
        param.put("isForCur", Integer.valueOf(isForCur));
    }

    private void analyzeDataType(Map<String, Object> param) {
        String dataTypeCondition = "";
        String dataTypeSumCondition = "";
        Object dataTypeObj = param.get("dataType");
        int isFromAccBalSum = ConvertUtil.toInt(param.get("isFromAccBalSum"));
        Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
        boolean isShowAllWd = ConvertUtil.toBoolean(param.get("isShowAllWd"));
        if (dataTypeObj != null) {
            String sqlDataType = "";
            String dataType = ConvertUtil.toString(dataTypeObj);
            if (isFromAccBalSum == 1 && !isShowAllWd) {
                sqlDataType = ConvertUtil.toString(AccComprehensiveQueryDaoConst.DATATYPE_ENUM_KM.get(dataType));
            } else {
                Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
                if ((isOneDimQuery == null || isOneDimQuery == 0) && (dimClsIsSelectOneCol == null || dimClsIsSelectOneCol == 0) && !isShowAllWd) {
                    sqlDataType = ConvertUtil.toString(AccComprehensiveQueryDaoConst.DATATYPE_ENUM.get(dataType));
                } else {
                    sqlDataType = ConvertUtil.toString(AccComprehensiveQueryDaoConst.DATATYPE_ENUM_KM.get(dataType));
                }
            }

            dataTypeSumCondition = ConvertUtil.toString(AccComprehensiveQueryDaoConst.DATATYPE_ENUM_SUM.get(dataType));
            if (StringUtils.isNotEmpty(sqlDataType)) {
                dataTypeCondition = sqlDataType;
            }
        }

        param.put("dataTypeCondition", dataTypeCondition);
        param.put("dataTypeSumCondition", dataTypeSumCondition);
    }

    private void analyzeCompanyinfo(Map<String, Object> param) {
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        String pftCompid = Objects.isNull(param.get("selectPftCompId")) ? "" : ConvertUtil.toString(param.get("selectPftCompId"));
        if (mxdwQuery != null && mxdwQuery == 1) {
            param.put("companyinfo", "HZ_COMPID_TREE");
        } else {
            String accountYear = ConvertUtil.toString(param.get("accountYear"));
            String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
            String TableCompidCondition = "";
            String accbookid = ConvertUtil.toString(param.get("accbookid"));
            int returnCount = ConvertUtil.toInt(param.get("returnCount"));
            String companyinfo;
            if (returnCount == 0 && ConvertUtil.toString(param.get("selectcompid")).contains(",")) {
                companyinfo = MessageFormat.format(AccComprehensiveQueryDaoConst.GET_ANALYZECOMPANYINFO_SQL_DEFAULT, accbookid, accountYear, " AND COMP_ID IN (SELECT COMPID FROM HZ_COMPID_TREE) ", "");
                param.put("companyinfo", companyinfo);
            } else {
                companyinfo = "";
                if (StringUtils.isNotEmpty(pftCompid)) {
                    companyinfo = MessageFormat.format(" SELECT PROF_CEN COMPID, A.OWNER_COMP_ID , A.SUPE_COMP_ID PCOMPID,  A.PFT_COMP_NAME COMPNAME,IS_LEAF LEAF FROM ACC_PROFIT_CENTER A   WHERE A.FISC_YEA = {0} {1} ", accountYear, compidCondition);
                } else {
                    companyinfo = MessageFormat.format(AccComprehensiveQueryDaoConst.GET_ANALYZECOMPANYINFO_SQL_DEFAULT, 0, accountYear, compidCondition, "");
                }

                param.put("companyinfo", companyinfo);
                boolean hasAnalyze = ConvertUtil.toBoolean(param.get("hasAnalyze"));
                if (!hasAnalyze) {
                    log.info(companyinfo);
                }
            }
        }

    }

    private void analyzeParam(Map<String, Object> param) {
        this.analyzeSelectWdIsOneDim(param);
        this.analyzeDataType(param);
        this.analyAccountIsBetween(param);
        this.analyzeMoneyType(param);
        this.analyzeCompid(param);
        this.analyzeCompanyinfo(param);
        this.analyzeAccoStatus(param);
        this.analyzeSelectWd(param);
        this.analyzeDimAccSubCom(param);
    }

    private void analyzeParamPro(Map<String, Object> param) {
        boolean hasAnalyze = ConvertUtil.toBoolean(param.get("hasAnalyze"));
        AccConditionUtils.isAllMatch(new Boolean[]{hasAnalyze}).handleCondition(() -> {
            this.analyzeParamMin(param);
        }, () -> {
            this.analyzeParam(param);
        });
    }

    private void analyzeParamMin(Map<String, Object> param) {
        this.analyzeSelectWdIsOneDim(param);
        this.analyzeDataType(param);
        this.analyAccountIsBetween(param);
        this.analyzeMoneyType(param);
        this.analyzeCompid(param);
        this.analyzeCompanyinfo(param);
        this.analyzeAccoStatus(param);
        this.analyzeSelectWd(param);
        this.analyzeDimAccSubCom(param);
    }

    private void bulidDimCol(Map<String, Object> param) {
        int isFromAccBalSum = ConvertUtil.toInt(param.get("isFromAccBalSum"));
        boolean isShowAllWd = ConvertUtil.toBoolean(param.get("isShowAllWd"));
        if (isFromAccBalSum != 1 || isShowAllWd) {
            Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
            if (isOneDimQuery != null && isOneDimQuery != 0) {
                if (!isShowAllWd) {
                    this.bulidColByWdForOneDim(param);
                }
            } else {
                String queryModel = ConvertUtil.toString(param.get("queryModel"));
                if ("0".equals(queryModel)) {
                    if (!isShowAllWd) {
                        Object selectWdObj = param.get("selectWd");
                        if (selectWdObj != null) {
                            List<Map<String, Object>> selectWd = (List)selectWdObj;
                            this.bulidColByWd(param, selectWd);
                        }
                    }
                } else {
                    Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
                    if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                        this.bulidColByWdForOneDim(param);
                    } else {
                        this.bulidColByWdForDimCls(param);
                    }
                }
            }

        }
    }

    private void analyzeAccoStatus(Map<String, Object> param) {
        String accoStatus = ConvertUtil.toString(param.get("accoStatus"));
        StringBuilder accoStatusContion = new StringBuilder("");
        if ("1".equals(accoStatus)) {
            accoStatusContion.append(" AND A.ENTRY_MARK = 1 ");
        } else if ("2".equals(accoStatus)) {
            accoStatusContion.append(" AND A.ENTRY_MARK = 0 ");
        }

        param.put("accoStatusContion", accoStatusContion.toString());
    }

    private void analyzeDimAccSubCom(Map<String, Object> param) {
        Integer isSelectDim = ConvertUtil.toInteger(param.get("isSelectDim"));
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        StringBuilder wdCondition = new StringBuilder();
        if (isSelectDim == 1) {
            String dimAccComSubTable = "(" + ConvertUtil.toString(param.get("dimAccComSub")) + ") K";
            String kmAndDimAndAccSelectSql = ConvertUtil.toString(param.get("kmAndDimAndAccSelectSql"));
            String withTable = "";
            String selectCol = "";
            StringBuilder insetDimSql = new StringBuilder("INSERT INTO GT_ZW_WDBILLMX2 (KMID,ACCOUNT_ID,COMPID,ZDNAME,MONEY1,MONEY2,DXLXID,TYPEBZ,GLDXID,KMCAPTION ");
            if (isOneDimQuery != null && isOneDimQuery != 0) {
                insetDimSql.append(")");
                if (!StringUtils.isEmpty(kmAndDimAndAccSelectSql)) {
                    withTable = " KMACC L";
                    selectCol = "SELECT L.IID, L.ACCOUNT_ID, L.COMPID,L.ZDNAME,L.MONEY1,L.MONEY2, K.DIMTYPEID, K.DIMCLS, K.DIMVALUE, K.DIMGROUP FROM ";
                    insetDimSql.append(kmAndDimAndAccSelectSql);
                    insetDimSql.append(selectCol);
                    insetDimSql.append(withTable);
                    insetDimSql.append(",");
                    insetDimSql.append(dimAccComSubTable);
                } else {
                    selectCol = "SELECT NULL IID, NULL ACCOUNT_ID, NULL COMPID,NULL ZDNAME,NULL MONEY1,NULL MONEY2, K.DIMTYPEID, K.DIMCLS, K.DIMVALUE, K.DIMGROUP FROM";
                    if (DBUtil.isMySql()) {
                        selectCol = "SELECT 0 IID, 0 ACCOUNT_ID, '' COMPID,'' ZDNAME,0 MONEY1,0 MONEY2, K.DIMTYPEID, K.DIMCLS, K.DIMVALUE, K.DIMGROUP FROM";
                    }

                    insetDimSql.append(selectCol);
                    insetDimSql.append(dimAccComSubTable);
                }

                int isSelectDimValue = ConvertUtil.toInt(param.get("isSelectDimValue"));
                wdCondition.append("  A.DIM_CLS = Y.TYPEBZ AND A.DIM_TYPE_ID = Y.DXLXID ");
                if (isSelectDimValue == 1) {
                    wdCondition.append(" AND A.DIM_VAL = Y.GLDXID");
                }
            } else {
                Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
                Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
                if (dimClsIsSelectOneCol == null || dimClsIsSelectOneCol != 1 || mxdwQuery != null && mxdwQuery != 0) {
                    String wdCol = ConvertUtil.toString(param.get("wdCol"));
                    insetDimSql.append(wdCol);
                    insetDimSql.append(")");
                    if (!StringUtils.isEmpty(kmAndDimAndAccSelectSql)) {
                        withTable = " KMACC L";
                        selectCol = "SELECT L.IID, L.ACCOUNT_ID, L.COMPID,L.ZDNAME,L.MONEY1,L.MONEY2, K.DIMTYPEID, K.DIMCLS, K.DIMVALUE, K.DIMGROUP" + wdCol + " FROM ";
                        insetDimSql.append(kmAndDimAndAccSelectSql);
                        insetDimSql.append(selectCol);
                        insetDimSql.append(withTable);
                        insetDimSql.append(",");
                        insetDimSql.append(dimAccComSubTable);
                    } else {
                        selectCol = "SELECT NULL IID, NULL ACCOUNT_ID, NULL COMPID,NULL ZDNAME,NULL MONEY1,NULL MONEY2, K.DIMTYPEID, K.DIMCLS, K.DIMVALUE, K.DIMGROUP " + wdCol + " FROM";
                        if (DBUtil.isMySql()) {
                            selectCol = "SELECT 0 IID, 0 ACCOUNT_ID, '' COMPID,'' ZDNAME,0 MONEY1,0 MONEY2, K.DIMTYPEID, K.DIMCLS, K.DIMVALUE, K.DIMGROUP " + wdCol + " FROM";
                        }

                        insetDimSql.append(selectCol);
                        insetDimSql.append(dimAccComSubTable);
                    }

                    wdCondition.append(" A.DIM_GROUP = Y.KMCAPTION");
                } else {
                    insetDimSql.append(")");
                    if (!StringUtils.isEmpty(kmAndDimAndAccSelectSql)) {
                        withTable = " KMACC L";
                        selectCol = "SELECT L.IID, L.ACCOUNT_ID, L.COMPID,L.ZDNAME,L.MONEY1,L.MONEY2, K.DIMTYPEID, K.DIMCLS, K.DIMVALUE, K.DIMGROUP FROM ";
                        insetDimSql.append(kmAndDimAndAccSelectSql);
                        insetDimSql.append(selectCol);
                        insetDimSql.append(withTable);
                        insetDimSql.append(",");
                        insetDimSql.append(dimAccComSubTable);
                    } else {
                        selectCol = "SELECT NULL IID, NULL ACCOUNT_ID, NULL COMPID,NULL ZDNAME,NULL MONEY1,NULL MONEY2, K.DIMTYPEID, K.DIMCLS, K.DIMVALUE, K.DIMGROUP FROM";
                        if (DBUtil.isMySql()) {
                            selectCol = "SELECT 0 IID, 0 ACCOUNT_ID, '' COMPID,'' ZDNAME,0 MONEY1,0 MONEY2, K.DIMTYPEID, K.DIMCLS, K.DIMVALUE, K.DIMGROUP FROM";
                        }

                        insetDimSql.append(selectCol);
                        insetDimSql.append(dimAccComSubTable);
                    }

                    wdCondition.append("  A.DIM_CLS = Y.TYPEBZ AND A.DIM_TYPE_ID = Y.DXLXID ");
                    int isSelectDimValue = ConvertUtil.toInt(param.get("isSelectDimValue"));
                    if (isSelectDimValue == 1) {
                        wdCondition.append(" AND A.DIM_VAL = Y.GLDXID");
                    }
                }
            }

            String getGldxFilterOneDimForMerge = ConvertUtil.toString(param.get("getGldxFilterOneDimForMerge"));
            if (StringUtils.isNotEmpty(getGldxFilterOneDimForMerge)) {
                param.put("distinctHande", true);
                param.put("getGldxFilterOneDimForMerge", "");
                String tempDimAccComSub = ConvertUtil.toString(param.get("dimAccComSub"));
                param.put("dimAccComSub", getGldxFilterOneDimForMerge);
                this.analyzeDimAccSubCom(param);
                param.put("dimAccComSub", tempDimAccComSub);
            }

            log.info(insetDimSql.toString());
        }

        param.put("wdCondition", wdCondition.toString());
    }

    private void analyAccountIsBetween(Map<String, Object> param) {
        int accountIsBetween = 1;
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        int isSameAccount = 0;
        String accountIdCol = "";
        String accountIdWhere = "";
        String accoungIdGroup = "";
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                accountIdCol = " C.ACC_PERIOD ACCOUNT_ID, C.ACC_PD_NAME ZDNAME ";
                accountIdWhere = " AND C.ACC_PERIOD IN (" + beginAccountId + "," + endAccountId + ") ";
            } else {
                if (endAccountId.equals(beginAccountId)) {
                    isSameAccount = 1;
                }

                accountIsBetween = 0;
            }
        } else if ("1".equals(dateStatus)) {
            accountIdCol = " C.ACC_PERIOD ACCOUNT_ID, C.ACC_PD_NAME ZDNAME ";
            accountIdWhere = " AND C.ACC_PERIOD BETWEEN " + beginAccountId + " AND " + endAccountId;
        } else if ("2".equals(dateStatus)) {
            accountIdCol = " MAX(C.ACC_PERIOD) ACCOUNT_ID, C.ACC_SEASON ZDNAME";
            accountIdWhere = " AND C.ACC_PERIOD BETWEEN " + beginAccountId + " AND " + endAccountId;
            Calendar cald = Calendar.getInstance();
            Date newTtime = new Date();
            cald.setTime(newTtime);
            int curYear = cald.get(1);


            if (curYear == ConvertUtil.toInt(accountYear)) {
                String curAccountId = ConvertUtil.toString(param.get("curAccountId"));
                accountIdWhere = accountIdWhere + " AND C.ACC_PERIOD <= " + curAccountId;
                param.put("endAccount", curAccountId);
            }

            accoungIdGroup = " GROUP BY C.ACC_SEASON ";
        } else if ("3".equals(dateStatus)) {
            accountIsBetween = 0;
        }

        String accountIdSelectSql = " SELECT " + accountIdCol + " FROM ACC_PERIOD C, ACC_BOOK D  WHERE C.ACC_RANGE_ID = D.ACC_RANGE_ID  AND D.ACC_BOOK = " + accbookid + " AND C.ACC_YEAR = " + accountYear + accountIdWhere + accoungIdGroup;
        param.put("isSameAccount", Integer.valueOf(isSameAccount));
        param.put("accountIsBetween", Integer.valueOf(accountIsBetween));
        param.put("accountIdSelectSql", accountIdSelectSql);
    }

    private void analyzeSelectWdIsOneDim(Map<String, Object> param) {
        String mainType = "2";
        int isOneDimQuery = 0;
        int isSelectDim = 0;
        int selectWdLen = 0;
        int isYwMainAndOneDim = 0;
        int i = 0;
        int j = 0;
        Object selectWdObj = param.get("selectWd");
        int oneDimQueryIsSelectDimValue = 0;
        int isFromAccBalSum = 1;
        int dimClsIsSelectOneCol = 0;
        String queryModel = ConvertUtil.toString(param.get("queryModel"));
        if ("1".equals(queryModel)) {
            selectWdObj = param.get("schemeSelectWd");
        }

        Map<String, String> dimTypeIdAndName = new HashMap();
        if (selectWdObj != null) {
            List<Map<String, Object>> selectWd = (List)selectWdObj;
            if (!CollectionUtils.isEmpty(selectWd)) {
                selectWdLen = selectWd.size();
                if ("1".equals(queryModel)) {
                    String lxid = "";
                    Iterator var17 = selectWd.iterator();

                    label72:
                    while(true) {
                        List wdDetails;
                        do {
                            Map map;
                            String type;
                            do {
                                if (!var17.hasNext()) {
                                    break label72;
                                }

                                map = (Map)var17.next();
                                type = ConvertUtil.toString(map.get("type"));
                            } while("2".equals(type));

                            wdDetails = (List)map.get("wdDetails");
                        } while(CollectionUtils.isEmpty(wdDetails));

                        if (wdDetails.size() > 1) {
                            ++j;
                        }

                        ++i;
                        isFromAccBalSum = 0;

                        for(int k = 0; k < wdDetails.size(); ++k) {
                            Map<String, Object> wdDetail = (Map)wdDetails.get(k);
                            lxid = ConvertUtil.toString(wdDetail.get("lxid"));
                            dimTypeIdAndName.put(ConvertUtil.toString(wdDetail.get("wdname")), lxid);
                        }
                    }
                } else {
                    if (param.get("queryFrom") == null) {
                        mainType = ConvertUtil.toString(((Map)selectWd.get(0)).get("type"));
                    }

                    Iterator var23 = selectWd.iterator();

                    while(var23.hasNext()) {
                        Map<String, Object> map = (Map)var23.next();
                        String type = ConvertUtil.toString(map.get("type"));
                        if (!"2".equals(type)) {
                            ++i;
                            isFromAccBalSum = 0;
                        }
                    }
                }
            }
        }

        if (i == 1) {
            if (j == 0) {
                isOneDimQuery = 1;
                oneDimQueryIsSelectDimValue = 1;
            } else {
                dimClsIsSelectOneCol = 1;
            }
        }

        if (i > 0) {
            isSelectDim = 1;
        }

        if (mainType.equals("1") && selectWdLen == 1) {
            isYwMainAndOneDim = 1;
        }

        param.put("mainType", mainType);
        param.put("isFromAccBalSum", Integer.valueOf(isFromAccBalSum));
        param.put("isOneDimQuery", Integer.valueOf(isOneDimQuery));
        param.put("isSelectDim", Integer.valueOf(isSelectDim));
        param.put("dimClsIsSelectOneCol", Integer.valueOf(dimClsIsSelectOneCol));
        param.put("dimTypeIdAndName", dimTypeIdAndName);
        param.put("oneDimQueryIsSelectDimValue", Integer.valueOf(oneDimQueryIsSelectDimValue));
        param.put("isYwMainAndOneDim", Integer.valueOf(isYwMainAndOneDim));
    }

    private List<String> extractTableNames(String sql) {
        List<String> tableNames = new ArrayList();
        Pattern pattern = Pattern.compile("\\b(ACC_BAL_|ACC_PFT_BAL_|OSET_BAL_)\\w+\\b", 2);
        Matcher matcher = pattern.matcher(sql);

        while(matcher.find()) {
            tableNames.add(matcher.group());
        }

        return tableNames;
    }

    private List<String> extractColumnAliases(String sql) {
        String retSql = sql.replaceAll("\n", "").replaceAll("\t", "");
        List<String> aliases = new ArrayList();
        String selectClause = retSql.substring(retSql.indexOf("SELECT") + 6, retSql.indexOf("FROM")).trim();
        List<String> parts = this.splitSelectClause(selectClause);
        Pattern pattern = Pattern.compile("(\\w+)(?:\\s+AS\\s+)?(\\w+)?$", 2);
        Iterator var7 = parts.iterator();

        while(var7.hasNext()) {
            String part = (String)var7.next();
            Matcher matcher = pattern.matcher(part.trim());
            if (matcher.find()) {
                String alias = matcher.group(2) != null ? matcher.group(2) : matcher.group(1);
                aliases.add(alias);
            }
        }

        return aliases;
    }

    private List<String> splitSelectClause(String selectClause) {
        List<String> parts = new ArrayList();
        Stack<Character> stack = new Stack();
        int start = 0;

        for(int i = 0; i < selectClause.length(); ++i) {
            char c = selectClause.charAt(i);
            if (c == '(') {
                stack.push(c);
            } else if (c == ')') {
                if (!stack.isEmpty() && (Character)stack.peek() == '(') {
                    stack.pop();
                }
            } else if (c == ',' && stack.isEmpty()) {
                parts.add(selectClause.substring(start, i));
                start = i + 1;
            }
        }

        parts.add(selectClause.substring(start));
        return parts;
    }

    private String addLimitCondition(Map<String, Object> param, String findSql) {
        boolean isKmWdQuery = ConvertUtil.toBoolean(param.get("isKmWdQuery"));
        if (!isKmWdQuery) {
            return findSql;
        } else if (!findSql.contains("LIMIT") && !findSql.contains("ROWNUM")) {
            int returnCount = ConvertUtil.toInt(param.get("returnCount"));
            if (returnCount <= 0) {
                return findSql;
            } else {
                String rowNum = "";
                if (DBUtil.isMySql()) {
                    rowNum = " LIMIT " + returnCount;
                } else {
                    rowNum = " ROWNUM<=" + returnCount;
                }

                String retSql = findSql.trim().toUpperCase();
                String conditionStr = retSql.substring(retSql.lastIndexOf("WHERE")).trim();
                if (StringUtils.isNotEmpty(conditionStr) && !conditionStr.contains("ORDER") && !conditionStr.contains("GROUP")) {
                    retSql = retSql + (DBUtil.isMySql() ? "" : " AND") + rowNum;
                } else {
                    List<String> aliases = this.extractColumnAliases(retSql);
                    String columns = String.join(",", aliases);
                    if (StringUtils.isNotEmpty(columns)) {
                        retSql = retSql.substring(0, retSql.indexOf("SELECT")) + " SELECT " + columns + " FROM (" + retSql.substring(retSql.indexOf("SELECT")) + ") MM WHERE" + rowNum;
                    }
                }

                return retSql;
            }
        } else {
            return findSql;
        }
    }

    private String buildTempTableInGt(Map<String, Object> param, String findSqlInput) {
        String returnFindSql = "";
        String returnQtyFindSql = "";
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        int isFromAccBalSum = ConvertUtil.toInt(param.get("isFromAccBalSum"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        boolean isShowAllWd = ConvertUtil.toBoolean(param.get("isShowAllWd"));
        boolean isNeedDealOther = false;
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
        Integer isShowAllWdHaveOrOneDim = ConvertUtil.toInteger(param.get("isShowAllWdHaveOrOneDim"));
        if (isFromAccBalSum == 1 && !isShowAllWd || isShowAllWd && isShowAllWdHaveOrOneDim != null && isShowAllWdHaveOrOneDim == 0) {
            Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
            String dataOption = ConvertUtil.toString(param.get("dataOption"));
            String bzlx = "";
            if ("MERGEDATA".equals(dataOption) && mxdwQuery != null && mxdwQuery == 1) {
                bzlx = " ,bzlx ";
            }

            returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.NOCOL_FOR_ROW_HZ_TEMP_CQUERY, findSqlInput, bzlx, "");
            String allMoney;
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                allMoney = ConvertUtil.toString(param.get("qtyFindSql"));
                returnQtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.NOCOL_FOR_ROW_HZ_TEMP_CQUERY, allMoney, bzlx, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL,\n\t\t\t\tBZLX");
            }

            if (isForCur == 1) {
                allMoney = "";
                if (moneyType == -3) {
                    allMoney = ",MONEY2";
                }

                returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.NOCOL_FOR_ROW_HZ_TEMP_CQUERY_FOR_CUR, findSqlInput, bzlx, allMoney, "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    String qtyFindSql = ConvertUtil.toString(param.get("qtyFindSql"));
                    returnQtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.NOCOL_FOR_ROW_HZ_TEMP_CQUERY_FOR_CUR, qtyFindSql, bzlx, allMoney, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL,\n\t\t\t\tBZLX");
                }
            }
        } else if (isOneDimQuery != null && isOneDimQuery != 0) {
            returnFindSql = this.buildTempTableInGtForOneDim(param, findSqlInput);
            isNeedDealOther = true;
        } else if (isShowAllWd) {
            returnFindSql = this.buildTempTableInGtForShowAllDim(param, findSqlInput);
        } else if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol != 0) {
            returnFindSql = this.buildTempTableInGtForDimClsIOneCol(param, findSqlInput);
            isNeedDealOther = true;
        } else {
            returnFindSql = this.buildTempTableInGtForNoOneDim(param, findSqlInput);
        }

        if (!isShowAllWd || isShowAllWdHaveOrOneDim != null && isShowAllWdHaveOrOneDim == 0) {
            if (!this.isNcYe(param)) {
            }

            List<String> replaceTabNameList = new ArrayList();
            if (returnFindSql.contains("GT_ZW_WDBILLMX2")) {
                replaceTabNameList.add("GT_ZW_WDBILLMX2");
            }

            if (returnFindSql.contains("GT_KMSRCTAB")) {
                replaceTabNameList.add("GT_KMSRCTAB");
            }

            this.handJzsyPz(param, replaceTabNameList);
            returnFindSql = AccComprehensiveQueryConvertSqlDao.convertInsertWdBillMxSql(returnFindSql, param);
            log.info(returnFindSql);
            if (StringUtils.isEmpty(returnQtyFindSql)) {
                returnQtyFindSql = ConvertUtil.toString(param.get("returnQtyFindSql"));
            }

            if (StringUtils.isNotEmpty(returnQtyFindSql)) {
                log.info(returnFindSql);

            }

            if (isNeedDealOther && DBUtil.isMySql()) {
                this.buildTempTableInGtOther(param);
            }

            this.insertEmptyDimData2GT(param, returnFindSql);
        }

        returnFindSql = AccComprehensiveQueryConvertSqlDao.convertInsertWdBillMxSql(returnFindSql, param);
        return returnFindSql;
    }

    private void handJzsyPz(Map<String, Object> param, List<String> replaceTabNameList) {
        if (null != ConvertUtil.toInteger(param.get("isContainProfitLoss")) && 1 == ConvertUtil.toInteger(param.get("isContainProfitLoss"))) {
            replaceTabNameList.add("GT_KMDESTTAB");
            String fiscYea = ConvertUtil.toString(param.get("accountYear"));
            String selectCompId = ConvertUtil.toString(param.get("selectcompid"));
            String beginAccPdId = ConvertUtil.toString(param.get("endAccount"));
            String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
            String forCurCondition = "";
            String selectCondition = "";
            String allCurrencySql = "";
            String pftCompIdSql = "";
            String allMoney = "";
            String groupCondition = " GROUP BY MX.ACC_SUB,MAIN.ACC_PERIOD ";
            if (StringUtils.isNotBlank(selectPftCompId)) {
                pftCompIdSql = "AND MAIN.PROF_CEN = " + selectPftCompId;
            }

            if (!Objects.isNull(param.get("moneyType")) && 1 != ConvertUtil.toInteger(param.get("moneyType"))) {
                if (-1 == ConvertUtil.toInteger(param.get("moneyType"))) {
                    forCurCondition = "AND (MX.FOR_CUR IS NULL OR MX.FOR_CUR = 0) ";
                } else if (-3 == ConvertUtil.toInteger(param.get("moneyType"))) {
                    groupCondition = " GROUP BY MX.ACC_SUB,MAIN.ACC_PERIOD,MX.FOR_CUR";
                    selectCondition = " ,(CASE WHEN (MX.FOR_CUR IS NULL OR MX.FOR_CUR = 0) THEN -1 ELSE MX.FOR_CUR END) FOR_CUR ";
                    allMoney = ",MONEY2";
                    allCurrencySql = MessageFormat.format(" UNION  SELECT '''' ZDNAME, ''{1}'' COMPID, MX.ACC_SUB KMID, 0 QCYE, 0 QCYE_BWB, 0 SUM_WB_J, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_J, 0 SUM_WB_D, SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_D, 0 QMYE, 0 QMYE_BWB, 0 SUM_WB_JL, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_JL, 0 SUM_WB_DL, SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_DL, MAIN.ACC_PERIOD ACCOUNT_ID,-3 MONEY2 FROM  ACC_VOUCH{0} MAIN JOIN ACC_VOUCH_DTL{0} MX ON  MAIN.BILL_ID = MX.BILL_ID JOIN GT_KMDESTTAB D ON D.IID = MX.ACC_SUB AND D.LEAF = 1 JOIN ACC_MON_CAR_ITEM_STAT C ON MAIN.BILL_ID = C.BILL_ID  WHERE  MAIN.FINA_ORG = ''{1}''  AND MAIN.ACC_BOOK = 0 {3}  AND MAIN.ACC_PERIOD = {2}  AND MAIN.FINISH_SUM_FLAG = 1 GROUP BY MX.ACC_SUB,MAIN.ACC_PERIOD", fiscYea, selectCompId, beginAccPdId, pftCompIdSql);
                } else {
                    forCurCondition = "AND MX.FOR_CUR = " + param.get("moneyType");
                }
            }

            String profitLossFindSql = MessageFormat.format("SELECT NULL ZDNAME, ''{1}'' COMPID, MX.ACC_SUB KMID, 0 QCYE, 0 QCYE_BWB, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.FOR_CY_AMT ELSE 0 END) * -1 SUM_WB_J, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_J, SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.FOR_CY_AMT ELSE 0 END) * -1 SUM_WB_D,  SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_D, 0 QMYE, 0 QMYE_BWB, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.FOR_CY_AMT ELSE 0 END) * -1 SUM_WB_LJ, SUM(CASE MX.LOAN_SIGN WHEN 0 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_LJ, SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.FOR_CY_AMT ELSE 0 END) * -1 SUM_WB_LD,  SUM(CASE MX.LOAN_SIGN WHEN 1 THEN MX.STD_CUR_AMT ELSE 0 END) * -1 SUM_LD, MAIN.ACC_PERIOD ACCOUNT_ID{5} FROM ACC_VOUCH{0} MAIN JOIN ACC_VOUCH_DTL{0} MX ON MAIN.BILL_ID = MX.BILL_ID JOIN GT_KMDESTTAB D ON D.IID = MX.ACC_SUB AND D.LEAF = 1 JOIN ACC_MON_CAR_ITEM_STAT C ON MAIN.BILL_ID = C.BILL_ID  WHERE MAIN.FINA_ORG = ''{1}'' AND MAIN.ACC_PERIOD = {2}   AND MAIN.FINISH_SUM_FLAG = 1  AND MAIN.ACC_BOOK = 0 {7} {3} {4} {6}", fiscYea, selectCompId, beginAccPdId, forCurCondition, groupCondition, selectCondition, allCurrencySql, pftCompIdSql);
            String profitLossInsertSql = MessageFormat.format(AccComprehensiveQueryDaoConst.NOCOL_FOR_ROW_HZ_TEMP_CQUERY_FOR_CUR, profitLossFindSql, "", allMoney, "");
            log.info(profitLossInsertSql);
        }

    }

    private void insertEmptyDimData2GT(Map<String, Object> param, String returnFindSql) {
        String findSqlShowEmptyDimValue = ConvertUtil.toString(param.get("findSqlShowEmptyDimValue"));
        if (StringUtils.isNotEmpty(findSqlShowEmptyDimValue)) {
            String findSqlEmptyDV = returnFindSql.substring(0, returnFindSql.indexOf(")") + 1);
            findSqlEmptyDV = findSqlEmptyDV + " " + findSqlShowEmptyDimValue;
            List<String> replaceTables = new ArrayList();
            if (DBUtil.isMySql()) {
                replaceTables.add("GT_ZW_WDBILLMX2");
                replaceTables.add("GT_ZW_WDBILLMX");
                replaceTables.add("GT_KMSRCTAB");
            }
            log.info(findSqlEmptyDV);
        }

    }





    private Map<Integer, String> getWdColMap(Map<String, Object> param) {
        Map<Integer, String> map = new HashMap();
        boolean isShowAllWd = ConvertUtil.toBoolean(param.get("isShowAllWd"));
        if (isShowAllWd) {
            map.put(0, ",F_LONG_CHAR1");
            map.put(1, ",KMCAPTION");
            map.put(2, ",A.KMCAPTION");
            map.put(3, "AND A.KMCAPTION = B.KMCAPTION ");
        } else {
            String wd = ConvertUtil.toString(param.get("wdCol"));
            if (Objects.isNull(wd)) {
                wd = "";
            }

            List<String> list = (List)Arrays.stream(wd.trim().split(",")).map(String::trim).filter((s) -> {
                return !s.isEmpty();
            }).collect(Collectors.toList());
            StringBuilder fNum = new StringBuilder();
            StringBuilder selectField = new StringBuilder();
            StringBuilder condition = new StringBuilder();

            for(int i = 0; i < list.size(); ++i) {
                int index = i + 1;
                fNum.append(",F_NUM").append(index);
                selectField.append(",A.").append((String)list.get(i));
                condition.append(" AND A.").append((String)list.get(i)).append(" = B.").append((String)list.get(i));
            }

            map.put(0, fNum.toString());
            map.put(1, wd);
            map.put(2, selectField.toString());
            map.put(3, condition.toString());
        }

        return map;
    }

    private void buildTempTableInGtOther(Map<String, Object> param) {
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        String[] wdCols = wdCol.split(",");
        StringBuilder leftJoinTable = new StringBuilder("");
        StringBuilder selectCol = new StringBuilder("");
        int i = 0;
        String[] var9 = wdCols;
        int var10 = wdCols.length;

        String exceSql;
        for(int var11 = 0; var11 < var10; ++var11) {
            exceSql = var9[var11];
            if (StringUtils.isNotEmpty(exceSql)) {
                leftJoinTable.append(" LEFT JOIN ACC_OBJ_MER_REL F");
                leftJoinTable.append(i);
                leftJoinTable.append(" ON A.");
                leftJoinTable.append(exceSql);
                leftJoinTable.append(" = F");
                leftJoinTable.append(i);
                leftJoinTable.append(".OBJ_ITEM_ID ");
                selectCol.append(", COALESCE(F");
                selectCol.append(i);
                selectCol.append(".OBJ_ID1,A.");
                selectCol.append(exceSql);
                selectCol.append(")");
            }

            ++i;
        }

        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String bzlx = "";
        if ("MERGEDATA".equals(dataOption) && mxdwQuery != null && mxdwQuery == 1) {
            bzlx = " ,BZLX ";
        }

        exceSql = MessageFormat.format(AccComprehensiveQueryDaoConst.INSERT_RESULT_IN_HZ_TEMP_ONE_DIM, wdCol, selectCol.toString(), leftJoinTable.toString(), bzlx, "", "", "");
        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
            exceSql = MessageFormat.format(AccComprehensiveQueryDaoConst.INSERT_RESULT_IN_HZ_TEMP_ONE_DIM, wdCol, selectCol.toString(), leftJoinTable.toString(), bzlx, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL\n\t\t\t\t", ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tSUM(WD51),SUM(QCYE_HL),\n\t\t\t\tSUM(WD52),SUM(SUM_SL_J),\n\t\t\t\tSUM(WD53),SUM(SUM_SL_D),\n\t\t\t\tSUM(WD54),SUM(QMYE_HL),\n\t\t\t\tSUM(WD55),SUM(SUM_SL_JL),\n\t\t\t\tSUM(WD56),SUM(SUM_SL_DL)\n\t\t\t\t", ",NUMTYPE,NUMSCALETYPE ");
        }

        if (isForCur == 1) {
            String allMoney = "";
            if (moneyType == -3) {
                allMoney = ",MONEY2";
            }

            exceSql = MessageFormat.format(AccComprehensiveQueryDaoConst.INSERT_RESULT_IN_HZ_TEMP_ONE_DIM_FOR_CUR, wdCol, selectCol.toString(), leftJoinTable.toString(), bzlx, allMoney, "", "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                exceSql = MessageFormat.format(AccComprehensiveQueryDaoConst.INSERT_RESULT_IN_HZ_TEMP_ONE_DIM_FOR_CUR, wdCol, selectCol.toString(), leftJoinTable.toString(), bzlx, allMoney, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL\n\t\t\t\t", ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tSUM(WD51),SUM(QCYE_HL),\n\t\t\t\tSUM(WD52),SUM(SUM_SL_J),\n\t\t\t\tSUM(WD53),SUM(SUM_SL_D),\n\t\t\t\tSUM(WD54),SUM(QMYE_HL),\n\t\t\t\tSUM(WD55),SUM(SUM_SL_JL),\n\t\t\t\tSUM(WD56),SUM(SUM_SL_DL)\n\t\t\t\t", ",NUMTYPE,NUMSCALETYPE ");
            }
        }

        exceSql = AccComprehensiveQueryConvertSqlDao.convertInsertWdBillMxQtSql(exceSql, param);
        log.info(exceSql);
    }

    private String buildTempTableInGtForNoOneDim(Map<String, Object> param, String findSql) {
        String returnFindSql = "";
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        String dataType = ConvertUtil.toString(param.get("dataType"));
        String dataTypeCondition = ConvertUtil.toString(AccComprehensiveQueryDaoConst.DATATYPE_ENUM_KM_FOR_WD.get(dataType));
        String dataCon = "";
        if (StringUtils.isNotEmpty(dataTypeCondition)) {
            dataCon = " HAVING " + dataTypeCondition.replaceAll("A\\.", "A1.");
        }

        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = "";
        String bzlx = "";
        if ("MERGEDATA".equals(dataOption) && mxdwQuery != null && mxdwQuery == 1) {
            bzlx = " ,bzlx ";
        }

        returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY, findSql, wdCol, dataCon, bzlx, "", "", "");
        String qtyFindSql;
        String returnQtyFindSql;
        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
            qtyFindSql = ConvertUtil.toString(param.get("qtyFindSql"));
            returnQtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY, qtyFindSql, wdCol, dataCon, bzlx, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL,\n\t\t\t\tBZLX", " ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       SUM(A1.QCYE_SL),SUM(A1.QCYE_DJ),\n\t       SUM(A1.SUM_J_SL),SUM(A1.SUM_J_DJ),\n\t       SUM(A1.SUM_D_SL),SUM(A1.SUM_D_DJ),\n\t       SUM(A1.QMYE_SL),SUM(A1.QMYE_DJ),\n\t       SUM(A1.SUM_JL_SL),SUM(A1.SUM_JL_DJ),\n\t       SUM(A1.SUM_DL_SL),SUM(A1.SUM_DL_DJ),\n\t       BZLX", " ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, A1.BZLX ");
            returnQtyFindSql = returnQtyFindSql.replace("DIM_VAL", "DTL_DIM_ID");
            param.put("returnQtyFindSql", returnQtyFindSql);
        }

        if (isForCur == 1) {
            if (moneyType == -3) {
                allMoney = ",MONEY2";
                allSelectMoney = ",FOR_CUR";
            }

            returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY_FOR_CUR, findSql, wdCol, dataCon, bzlx, allMoney, allSelectMoney, "", "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = ConvertUtil.toString(param.get("qtyFindSql"));
                returnQtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY_FOR_CUR, qtyFindSql, wdCol, dataCon, bzlx, allMoney, allSelectMoney, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL,\n\t\t\t\tBZLX", " ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       SUM(A1.QCYE_SL),SUM(A1.QCYE_DJ),\n\t       SUM(A1.SUM_J_SL),SUM(A1.SUM_J_DJ),\n\t       SUM(A1.SUM_D_SL),SUM(A1.SUM_D_DJ),\n\t       SUM(A1.QMYE_SL),SUM(A1.QMYE_DJ),\n\t       SUM(A1.SUM_JL_SL),SUM(A1.SUM_JL_DJ),\n\t       SUM(A1.SUM_DL_SL),SUM(A1.SUM_DL_DJ),\n\t       BZLX", " ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, A1.BZLX ");
                returnQtyFindSql = returnQtyFindSql.replace("DIM_VAL", "DTL_DIM_ID");
                param.put("returnQtyFindSql", returnQtyFindSql);
            }
        }

        return returnFindSql;
    }

    private String buildTempTableInGtForDimClsIOneCol(Map<String, Object> param, String findSql) {
        String returnFindSql = "";
        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        String dataTypeCondition = ConvertUtil.toString(param.get("dataTypeCondition"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        String dataCon = "";
        String rowNum = "";
        if (StringUtils.isNotEmpty(dataTypeCondition)) {
            dataCon = " WHERE " + dataTypeCondition.replaceAll("A\\.", "A1.");
            if (returnCount != 0) {
                if (DBUtil.isMySql()) {
                    if (ConvertUtil.toBoolean(param.get("export"))) {
                        rowNum = " ";
                    } else {
                        rowNum = " LIMIT " + returnCount;
                    }
                } else {
                    rowNum = " AND ROWNUM<=" + returnCount;
                }
            }
        } else if (returnCount != 0) {
            if (DBUtil.isMySql()) {
                if (ConvertUtil.toBoolean(param.get("export"))) {
                    rowNum = " ";
                } else {
                    rowNum = " LIMIT " + returnCount;
                }
            } else {
                rowNum = " WHERE ROWNUM<=" + returnCount;
            }
        }

        returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY_ONE_DIM_CLS, findSql, wdCol, dataCon, rowNum);
        if (isForCur == 1) {
            returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY_ONE_DIM_CLS_FOR_CUR, findSql, wdCol, dataCon, rowNum);
        }

        return returnFindSql;
    }

    private String buildTempTableInGtForShowAllDim(Map<String, Object> param, String findSql) {
        String returnFindSql = "";
        String returnQtyFindSql = "";
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SHOW_ALL_DIM_FOR_TEMP_CQUERY, findSql, "");
        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
            String qtyFindSql = ConvertUtil.toString(param.get("qtyFindSql"));
            returnQtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SHOW_ALL_DIM_FOR_TEMP_CQUERY, qtyFindSql, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL,\n\t\t\t\tBZLX");
            returnQtyFindSql = returnQtyFindSql.replace("DIM_VAL", "DTL_DIM_ID");
            param.put("returnQtyFindSql", returnQtyFindSql);
        }

        List<String> replaceTabNameList = new ArrayList();
        replaceTabNameList.add("GT_ZW_WDBILLMX2");
        String xjmxCondition;
        if (isForCur == 1) {
            xjmxCondition = "";
            if (moneyType == -3) {
                xjmxCondition = ",MONEY2";
            }

            returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SHOW_ALL_DIM_FOR_TEMP_CQUERY_FOR_CUR, findSql, xjmxCondition, "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                String qtyFindSql = ConvertUtil.toString(param.get("qtyFindSql"));
                returnQtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SHOW_ALL_DIM_FOR_TEMP_CQUERY_FOR_CUR, qtyFindSql, xjmxCondition, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL,\n\t\t\t\tBZLX");
                returnQtyFindSql = returnQtyFindSql.replace("DIM_VAL", "DTL_DIM_ID");
                param.put("returnQtyFindSql", returnQtyFindSql);
            }
        }

        if (!this.isNcYe(param)) {
        }
        log.info(returnFindSql);
        if (StringUtils.isEmpty(returnQtyFindSql)) {
            returnQtyFindSql = ConvertUtil.toString(param.get("returnQtyFindSql"));
        }

        if (StringUtils.isNotEmpty(returnQtyFindSql)) {
            log.info(returnFindSql);
            if (isForCur == 1) {
            } else {
            }
        }

        this.insertEmptyDimData2GT(param, returnFindSql);
        xjmxCondition = " ";
        boolean isXjmx = ConvertUtil.toBoolean(param.get("xjmx"));
        if (isXjmx && !ConvertUtil.toBoolean(param.get("dimAndShowAllDim"))) {
            xjmxCondition = " AND A.DIM_CLS = 0 ";
        }
        log.info(MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_FROM_DIM_GROUP, xjmxCondition), new ArrayList(), new HashMap(), Map.class, param);
        AccComprehensiveQueryConvertSqlDao.changeListOrder(param);


        this.bulidColByWdForKm(param);
        
        String colToRowWdCol = ConvertUtil.toString(param.get("colToRowWdCol"));
        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        String wdColCondition = "";
        if (isXjmx) {
            wdColCondition = this.getNotNullWdColStr(wdCol, param);
        }

        String colToRowSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SHOW_ALL_DIM_FOR_COL, wdCol, colToRowWdCol, wdColCondition);
        log.info(colToRowSql);
        String inserSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SHOW_ALL_DIM_INTO_TEMP, wdCol, wdCol.replaceAll("DIM", "B.DIM"), "", "");
        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
            inserSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SHOW_ALL_DIM_INTO_TEMP, wdCol, wdCol.replaceAll("DIM", "B.DIM"), "\t\t\t   ,NUMTYPE,NUMSCALETYPE,\n                WD51,QCYE_HL,\n                WD52,SUM_SL_J,\n                WD53,SUM_SL_D,\n                WD54,QMYE_HL,\n                WD55,SUM_SL_JL,\n                WD56,SUM_SL_DL ", "\t\t\t         \t\t\t   ,A.NUMTYPE,A.NUMSCALETYPE,\n                A.WD51,A.QCYE_HL,\n                A.WD52,A.SUM_SL_J,\n                A.WD53,A.SUM_SL_D,\n                A.WD54,A.QMYE_HL,\n                A.WD55,A.SUM_SL_JL,\n                A.WD56,A.SUM_SL_DL ");
        }

        if (isForCur == 1) {
            String allMoney = "";
            String orderByAllMoney = "";
            if (moneyType == -3) {
                allMoney = ",A.MONEY2";
                orderByAllMoney = " , MONEY2 ";
            }

            inserSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SHOW_ALL_DIM_INTO_TEMP_FOR_CUR, wdCol, wdCol.replaceAll("DIM", "B.DIM"), allMoney, orderByAllMoney, "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                inserSql = MessageFormat.format(AccComprehensiveQueryDaoConst.SHOW_ALL_DIM_INTO_TEMP_FOR_CUR, wdCol, wdCol.replaceAll("DIM", "B.DIM"), allMoney, orderByAllMoney, "\t\t\t   ,NUMTYPE,NUMSCALETYPE,\n                WD51,QCYE_HL,\n                WD52,SUM_SL_J,\n                WD53,SUM_SL_D,\n                WD54,QMYE_HL,\n                WD55,SUM_SL_JL,\n                WD56,SUM_SL_DL ", "\t\t\t         \t\t\t   ,A.NUMTYPE,A.NUMSCALETYPE,\n                A.WD51,A.QCYE_HL,\n                A.WD52,A.SUM_SL_J,\n                A.WD53,A.SUM_SL_D,\n                A.WD54,A.QMYE_HL,\n                A.WD55,A.SUM_SL_JL,\n                A.WD56,A.SUM_SL_DL ");
            }
        }

        replaceTabNameList.add("GT_ZW_WDBILLMX");
        replaceTabNameList.add("GT_KMDESTTAB");
        log.info(AccComprehensiveQueryDaoConst.DELETE_SHOW_ALL_DIM_BZXZ_0);
        return returnFindSql;
    }

    private String buildTempTableInGtForOneDim(Map<String, Object> param, String findSql) {
        String returnFindSql = "";
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        boolean isShowAllWd = ConvertUtil.toBoolean(param.get("isShowAllWd"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String dataTypeCondition = ConvertUtil.toString(param.get("dataTypeCondition"));
        String dataCon = "";
        String rowNum = "";
        if (StringUtils.isNotEmpty(dataTypeCondition)) {
            dataCon = " WHERE " + dataTypeCondition.replaceAll("A\\.", "A1.");
            if (returnCount != 0 && isShowAllWd) {
                if (DBUtil.isMySql()) {
                    if (ConvertUtil.toBoolean(param.get("export"))) {
                        rowNum = " ";
                    } else {
                        rowNum = " LIMIT " + returnCount;
                    }
                } else {
                    rowNum = " AND ROWNUM<=" + returnCount;
                }
            }
        } else if (returnCount != 0 && isShowAllWd) {
            if (DBUtil.isMySql()) {
                if (ConvertUtil.toBoolean(param.get("export"))) {
                    rowNum = " ";
                } else {
                    rowNum = " LIMIT " + returnCount;
                }
            } else {
                rowNum = " WHERE ROWNUM<=" + returnCount;
            }
        }

        String kmCondition = " KMID,";
        String subjectCondition = " A1.SUBJECT_ID, ";
        boolean isOneDim = param.get("isYwMainAndOneDim") != null && ConvertUtil.toInt(param.get("isYwMainAndOneDim")) == 1;
        if (isOneDim) {
            kmCondition = "";
            subjectCondition = "";
        }

        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String bzlx = "";
        if ("MERGEDATA".equals(dataOption) && mxdwQuery != null && mxdwQuery == 1) {
            bzlx = " ,BZLX ";
        }

        returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY_ONE_DIM, findSql, wdCol, dataCon, rowNum, kmCondition, subjectCondition, bzlx, "", "");
        String allMoney;
        String allSelectMoney;
        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
            allMoney = ConvertUtil.toString(param.get("qtyFindSql"));
            allSelectMoney = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY_ONE_DIM, allMoney, wdCol, dataCon, rowNum, kmCondition, subjectCondition, bzlx, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL,\n\t\t\t\tBZLX", "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX");
            allSelectMoney = allSelectMoney.replace("DIM_VAL", "DTL_DIM_ID");
            param.put("returnQtyFindSql", allSelectMoney);
        }

        allMoney = "";
        allSelectMoney = "";
        if (isForCur == 1) {
            if (moneyType == -3) {
                allSelectMoney = ",MONEY2";
                allMoney = ",FOR_CUR";
            }

            returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY_ONE_DIM_FOR_CUR, findSql, wdCol, dataCon, rowNum, kmCondition, subjectCondition, bzlx, allMoney, allSelectMoney, "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                String qtyFindSql = ConvertUtil.toString(param.get("qtyFindSql"));
                String returnQtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.COL_FOR_ROW_HZ_TEMP_CQUERY_ONE_DIM_FOR_CUR, qtyFindSql, wdCol, dataCon, rowNum, kmCondition, subjectCondition, bzlx, allMoney, allSelectMoney, ",NUMTYPE,NUMSCALETYPE,\n\t\t\t\tWD51,QCYE_HL,\n\t\t\t\tWD52,SUM_SL_J,\n\t\t\t\tWD53,SUM_SL_D,\n\t\t\t\tWD54,QMYE_HL,\n\t\t\t\tWD55,SUM_SL_JL,\n\t\t\t\tWD56,SUM_SL_DL,\n\t\t\t\tBZLX", "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX");
                returnQtyFindSql = returnQtyFindSql.replace("DIM_VAL", "DTL_DIM_ID");
                param.put("returnQtyFindSql", returnQtyFindSql);
            }
        }

        return returnFindSql;
    }

    private void bulidColByWdForKm(Map<String, Object> param) {
        StringBuilder rowCol = new StringBuilder("");
        StringBuilder qtRowCol = new StringBuilder("");
        StringBuilder qtGroupRowCol = new StringBuilder("");
        StringBuilder qtOrderRowCol = new StringBuilder("");
        StringBuilder selectRowCol = new StringBuilder("");
        StringBuilder rollupRowCon = new StringBuilder("");
        List<Map<String, Object>> allDimDyList = (List)param.get("allDimDyList");
        List<Map<String, Object>> showAllDims = new ArrayList();
        List<Map<String, Object>> kmWds = (List)param.get("subjectCacMap");
        int isGroupByDimGroup = 0;
        int oneDimIsCls = 0;
        if (!CollectionUtils.isEmpty(allDimDyList) && !CollectionUtils.isEmpty(kmWds)) {
            String type = "2";
            String dimlxid = "";
            String wdName = "";
            Map<String, String> dimNameMap = new HashMap();
            Iterator var17 = allDimDyList.iterator();

            label66:
            while(true) {
                while(true) {
                    Map dimMap;
                    do {
                        if (!var17.hasNext()) {
                            String wdlxid = "";
                            int i = 0;
                            StringBuilder wdIsNullCon = new StringBuilder("");
                            StringBuilder wdIsNotNullCon = new StringBuilder("");
                            Iterator var30 = kmWds.iterator();

                            while(var30.hasNext()) {
                                Map<String, Object> kmMap = (Map)var30.next();
                                wdlxid = ConvertUtil.toString(kmMap.get("dim_type_id"));
                                int dimType = ConvertUtil.toInt(kmMap.get("dim_cls"));
                                if (dimNameMap.get(wdlxid) != null) {
                                    wdName = (String)dimNameMap.get(wdlxid);
                                    qtRowCol.append(",");
                                    if (DBUtil.isMySql()) {
                                        qtRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                                        qtRowCol.append(wdName);
                                        qtRowCol.append(" ELSE NULL END) ");
                                        qtRowCol.append(wdName);
                                        qtGroupRowCol.append(",");
                                        qtGroupRowCol.append("( CASE A.LEAF WHEN 1 THEN ");
                                        qtGroupRowCol.append(wdName);
                                        qtGroupRowCol.append(" ELSE NULL END) ");
                                        qtOrderRowCol.append(",");
                                        qtOrderRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                                        qtOrderRowCol.append(wdName);
                                        qtOrderRowCol.append(" ELSE NULL END) ASC");
                                    } else {
                                        qtRowCol.append("DECODE(A.LEAF, 1, ");
                                        qtRowCol.append(wdName);
                                        qtRowCol.append(", NULL) ");
                                        qtRowCol.append(wdName);
                                        qtGroupRowCol.append(",");
                                        qtGroupRowCol.append("DECODE(A.LEAF, 1, ");
                                        qtGroupRowCol.append(wdName);
                                        qtGroupRowCol.append(", NULL) ");
                                        qtOrderRowCol.append(",");
                                        qtOrderRowCol.append("DECODE(A.LEAF, 1, ");
                                        qtOrderRowCol.append(wdName);
                                        qtOrderRowCol.append(", NULL) DESC");
                                    }

                                    rowCol.append(", ");
                                    rowCol.append(wdName);
                                    if (i == 0) {
                                        wdIsNullCon.append(wdName);
                                        wdIsNullCon.append(" IS NULL");
                                        wdIsNotNullCon.append(wdName);
                                        wdIsNotNullCon.append(" IS NOT NULL");
                                    } else {
                                        wdIsNullCon.append(" AND ");
                                        wdIsNullCon.append(wdName);
                                        wdIsNullCon.append(" IS NULL");
                                        wdIsNotNullCon.append(" AND ");
                                        wdIsNotNullCon.append(wdName);
                                        wdIsNotNullCon.append(" IS NOT NULL");
                                    }

                                    ++i;
                                    if (DBUtil.isMySql()) {
                                        selectRowCol.append(",MAX(CASE A.DIM_TYPE_ID WHEN '");
                                        selectRowCol.append(wdlxid);
                                        selectRowCol.append("' THEN A.DIM_VAL ELSE NULL END) ");
                                        selectRowCol.append(wdName);
                                    } else {
                                        selectRowCol.append(",MAX(DECODE(A.DIM_TYPE_ID,'");
                                        selectRowCol.append(wdlxid);
                                        selectRowCol.append("',A.DIM_VAL,NULL)) ");
                                        selectRowCol.append(wdName);
                                    }
                                }
                            }

                            if (StringUtils.isNotEmpty(wdIsNullCon.toString())) {
                                rollupRowCon.append("(");
                                rollupRowCon.append(wdIsNullCon.toString());
                                rollupRowCon.append(") OR (");
                                rollupRowCon.append(wdIsNotNullCon.toString());
                                rollupRowCon.append(")");
                            }
                            break label66;
                        }

                        dimMap = (Map)var17.next();
                        type = ConvertUtil.toString(dimMap.get("type"));
                    } while("2".equals(type));

                    dimlxid = ConvertUtil.toString(dimMap.get("lxid"));
                    wdName = ConvertUtil.toString(dimMap.get("wdname"));
                    if (dimlxid.contains(",")) {
                        String[] dimlxids = dimlxid.split(",");
                        String[] var20 = dimlxids;
                        int var21 = dimlxids.length;

                        for(int var22 = 0; var22 < var21; ++var22) {
                            String s = var20[var22];
                            dimNameMap.putIfAbsent(s, wdName);
                        }
                    } else {
                        dimNameMap.putIfAbsent(dimlxid, wdName);
                    }
                }
            }
        }



        param.put("isGroupByDimGroup", Integer.valueOf(isGroupByDimGroup));
        param.put("colToRowWdCol", selectRowCol.toString());
        param.put("wdCol", rowCol.toString());
        param.put("rollupRowCon", rollupRowCon.toString());
        param.put("qtRowCol", qtRowCol.toString());
        param.put("qtGroupRowCol", qtGroupRowCol.toString());
        param.put("qtOrderRowCol", qtOrderRowCol.toString());
        param.put("oneDimIsCls", Integer.valueOf(oneDimIsCls));
        param.put("showAllDims", showAllDims);
    }

    private void bulidColByWdForOneDim(Map<String, Object> param) {
        String queryModel = ConvertUtil.toString(param.get("queryModel"));
        if ("0".equals(queryModel)) {
            this.bulidColByWdForOneDimModel(param);
        } else {
            this.bulidColByWdForOneDimCls(param);
        }

    }

    private void bulidColByWdForOneDimCls(Map<String, Object> param) {
        StringBuilder rowCol = new StringBuilder("");
        StringBuilder qtRowCol = new StringBuilder("");
        StringBuilder qtGroupRowCol = new StringBuilder("");
        StringBuilder qtOrderRowCol = new StringBuilder("");
        StringBuilder selectRowCol = new StringBuilder("");
        Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
        String wdName = "";
        int oneDimIsCls = 0;
        String type = "";
        String lxid = "";
        int isGroupByDimGroup = 0;
        Object selectWdObj = param.get("schemeSelectWd");
        if (selectWdObj != null) {
            List<Map<String, Object>> selectWd = (List)selectWdObj;
            if (!CollectionUtils.isEmpty(selectWd)) {
                Iterator var16 = selectWd.iterator();

                label120:
                while(true) {
                    List wdDetails;
                    do {
                        Map map;
                        do {
                            if (!var16.hasNext()) {
                                break label120;
                            }

                            map = (Map)var16.next();
                            type = ConvertUtil.toString(map.get("type"));
                        } while("2".equals(type));

                        wdDetails = (List)map.get("wdDetails");
                    } while(CollectionUtils.isEmpty(wdDetails));

                    int wdDetailSize = wdDetails.size();
                    if (wdDetailSize > 1) {
                        isGroupByDimGroup = 1;
                    }

                    for(int j = 0; j < wdDetails.size(); ++j) {
                        Map<String, Object> wdDetail = (Map)wdDetails.get(j);
                        lxid = ConvertUtil.toString(wdDetail.get("lxid"));
                        wdName = ConvertUtil.toString(wdDetail.get("wdname"));
                        if (DBUtil.isMySql()) {
                            qtRowCol.append(",");
                            qtRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                            qtRowCol.append(wdName);
                            qtRowCol.append(" ELSE NULL END) ");
                            qtRowCol.append(wdName);
                            qtGroupRowCol.append(",");
                            qtGroupRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                            qtGroupRowCol.append(wdName);
                            qtGroupRowCol.append(" ELSE NULL END) ");
                            qtOrderRowCol.append(",");
                            qtOrderRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                            qtOrderRowCol.append(wdName);
                            qtOrderRowCol.append(" ELSE NULL END) ASC");
                        } else {
                            qtRowCol.append(",");
                            qtRowCol.append("DECODE(A.LEAF, 1, ");
                            qtRowCol.append(wdName);
                            qtRowCol.append(", NULL) ");
                            qtRowCol.append(wdName);
                            qtGroupRowCol.append(",");
                            qtGroupRowCol.append("DECODE(A.LEAF, 1, ");
                            qtGroupRowCol.append(wdName);
                            qtGroupRowCol.append(", NULL) ");
                            qtOrderRowCol.append(",");
                            qtOrderRowCol.append("DECODE(A.LEAF, 1, ");
                            qtOrderRowCol.append(wdName);
                            qtOrderRowCol.append(", NULL) DESC");
                        }

                        rowCol.append(", ");
                        rowCol.append(wdName);
                        selectRowCol.append(", ");
                        if (wdDetailSize == 1) {
                            if (DBUtil.isMySql()) {
                                selectRowCol.append(" A.DIM_VAL ");
                                selectRowCol.append(wdName);
                            } else {
                                selectRowCol.append("NVL(F.OBJ_ID1,A.DIM_VAL)");
                                selectRowCol.append(wdName);
                            }
                        } else if (!lxid.contains(",")) {
                            if (DBUtil.isMySql()) {
                                if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                                    selectRowCol.append("MAX");
                                }

                                selectRowCol.append("(CASE A.DIM_TYPE_ID WHEN '");
                                selectRowCol.append(lxid);
                                selectRowCol.append("' THEN A.DIM_VAL ELSE NULL END) ");
                                selectRowCol.append(wdName);
                            } else {
                                if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                                    selectRowCol.append("MAX(");
                                }

                                selectRowCol.append("DECODE(A.DIM_TYPE_ID,'");
                                selectRowCol.append(lxid);
                                selectRowCol.append("',NVL(F.OBJ_ID1,A.DIM_VAL),NULL) ");
                                if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                                    selectRowCol.append(") ");
                                }

                                selectRowCol.append(wdName);
                            }
                        } else {
                            String[] dxids = lxid.split(",");
                            if (DBUtil.isMySql()) {
                                if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                                    selectRowCol.append("MAX");
                                }

                                selectRowCol.append("(CASE A.DIM_TYPE_ID '");
                                selectRowCol.append(lxid);
                            } else {
                                selectRowCol.append("");
                            }

                            StringBuilder endS = new StringBuilder("");
                            String[] var24 = dxids;
                            int var25 = dxids.length;

                            for(int var26 = 0; var26 < var25; ++var26) {
                                String s = var24[var26];
                                if (DBUtil.isMySql()) {
                                    selectRowCol.append(" WHEN '");
                                    selectRowCol.append(lxid);
                                    selectRowCol.append("' THEN A.DIM_VAL ");
                                } else {
                                    if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                                        selectRowCol.append("MAX(");
                                    }

                                    selectRowCol.append("DECODE(A1.DIM_TYPE_ID,'");
                                    selectRowCol.append(s);
                                    selectRowCol.append("',NVL(F.OBJ_ID1,A.DIM_VAL),");
                                }

                                endS.append(")");
                            }

                            if (DBUtil.isMySql()) {
                                selectRowCol.append(" ELSE NULL END) ");
                                selectRowCol.append(wdName);
                            } else {
                                selectRowCol.append("NULL");
                                selectRowCol.append(endS.toString().substring(1));
                                selectRowCol.append(",NULL) ");
                                if (dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1) {
                                    selectRowCol.append(")");
                                }

                                selectRowCol.append(wdName);
                            }
                        }
                    }
                }
            }
        }



        param.put("isGroupByDimGroup", Integer.valueOf(isGroupByDimGroup));
        param.put("colToRowWdCol", selectRowCol.toString());
        param.put("wdCol", rowCol.toString());
        param.put("rollupRowCon", "");
        param.put("qtRowCol", qtRowCol.toString());
        param.put("qtGroupRowCol", qtGroupRowCol.toString());
        param.put("qtOrderRowCol", qtOrderRowCol.toString());
        param.put("oneDimIsCls", Integer.valueOf(oneDimIsCls));
    }

    private void bulidColByWdForOneDimModel(Map<String, Object> param) {
        StringBuilder rowCol = new StringBuilder("");
        StringBuilder qtRowCol = new StringBuilder("");
        StringBuilder qtGroupRowCol = new StringBuilder("");
        StringBuilder qtOrderRowCol = new StringBuilder("");
        StringBuilder selectRowCol = new StringBuilder("");
        int oneDimIsCls = 0;
        String wdName = "";
        String type = "";
        Object selectWdObj = param.get("selectWd");
        String maintype = ConvertUtil.toString(param.get("mainType"));
        int limitCount = ConvertUtil.toInt(param.get("hzDataLimit"));
        if (selectWdObj != null) {
            List<Map<String, Object>> selectWd = (List)selectWdObj;
            if (!CollectionUtils.isEmpty(selectWd)) {
                Iterator var14 = selectWd.iterator();

                while(var14.hasNext()) {
                    Map<String, Object> map = (Map)var14.next();
                    type = ConvertUtil.toString(map.get("type"));
                    if (!"2".equals(type)) {
                        wdName = ConvertUtil.toString(map.get("wdname"));
                        if ("1".equals(maintype)) {
                            if (DBUtil.isMySql()) {
                                if (!ConvertUtil.toBoolean(param.get("export"))) {
                                    qtRowCol.append(", '' ");
                                    qtGroupRowCol.append(", '' ");
                                } else {
                                    qtRowCol.append(",  ");
                                    qtGroupRowCol.append(",");
                                }
                            } else {
                                qtRowCol.append(",  ");
                                qtGroupRowCol.append(",  ");
                            }

                            qtRowCol.append(wdName);
                            qtGroupRowCol.append(wdName);
                        } else if (DBUtil.isMySql()) {
                            qtRowCol.append(",");
                            qtRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                            qtRowCol.append(wdName);
                            qtRowCol.append(" ELSE NULL END) ");
                            qtRowCol.append(wdName);
                            qtGroupRowCol.append(",");
                            qtGroupRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                            qtGroupRowCol.append(wdName);
                            qtGroupRowCol.append(" ELSE NULL END) ");
                            qtOrderRowCol.append(",");
                            qtOrderRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                            qtOrderRowCol.append(wdName);
                            qtOrderRowCol.append(" ELSE NULL END) ASC");
                        } else {
                            qtRowCol.append(",");
                            qtRowCol.append("DECODE(A.LEAF, 1, ");
                            qtRowCol.append(wdName);
                            qtRowCol.append(", NULL) ");
                            qtRowCol.append(wdName);
                            qtGroupRowCol.append(",");
                            qtGroupRowCol.append("DECODE(A.LEAF, 1, ");
                            qtGroupRowCol.append(wdName);
                            qtGroupRowCol.append(", NULL) ");
                            qtOrderRowCol.append(",");
                            qtOrderRowCol.append("DECODE(A.LEAF, 1, ");
                            qtOrderRowCol.append(wdName);
                            qtOrderRowCol.append(", NULL) DESC");
                        }

                        rowCol.append(", ");
                        rowCol.append(wdName);
                        selectRowCol.append(", ");
                        if (DBUtil.isMySql()) {
                            if ("1".equals(type)) {
                                oneDimIsCls = 1;
                            }

                            selectRowCol.append(" A.DIM_VAL ");
                            selectRowCol.append(wdName);
                        } else {
                            if ("1".equals(type)) {
                                selectRowCol.append("A.DIM_VAL ");
                                oneDimIsCls = 1;
                            } else if (limitCount > 0) {
                                selectRowCol.append("A.DIM_VAL ");
                            } else {
                                selectRowCol.append("NVL(F.OBJ_ID1,A.DIM_VAL) ");
                            }

                            selectRowCol.append(wdName);
                        }
                    }
                }
            }
        }



        param.put("isGroupByDimGroup", 0);
        param.put("colToRowWdCol", selectRowCol.toString());
        param.put("wdCol", rowCol.toString());
        param.put("rollupRowCon", "");
        param.put("qtRowCol", qtRowCol.toString());
        param.put("qtGroupRowCol", qtGroupRowCol.toString());
        param.put("qtOrderRowCol", qtOrderRowCol.toString());
        param.put("oneDimIsCls", Integer.valueOf(oneDimIsCls));
    }

    private void bulidColByWdForDimCls(Map<String, Object> param) {
        StringBuilder rowCol = new StringBuilder("");
        StringBuilder qtRowCol = new StringBuilder("");
        StringBuilder qtGroupRowCol = new StringBuilder("");
        StringBuilder qtOrderRowCol = new StringBuilder("");
        StringBuilder selectRowCol = new StringBuilder("");
        StringBuilder rollupRowCon = new StringBuilder("");
        Map<String, String> dimTypeIdAndName = new HashMap();
        if (param.get("dimTypeIdAndName") != null) {
            dimTypeIdAndName = (Map)param.get("dimTypeIdAndName");
        }

        String wdName = "";
        int i = 0;
        StringBuilder wdIsNullCon = new StringBuilder("");
        StringBuilder wdIsNotNullCon = new StringBuilder("");
        if (((Map)dimTypeIdAndName).size() > 0) {
            Iterator var13 = ((Map)dimTypeIdAndName).keySet().iterator();

            while(var13.hasNext()) {
                String key = (String)var13.next();
                String dimTypeId = (String)((Map)dimTypeIdAndName).get(key);
                if (DBUtil.isMySql()) {
                    qtRowCol.append(",");
                    qtRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                    qtRowCol.append(key);
                    qtRowCol.append(" ELSE '' END) ");
                    qtRowCol.append(key);
                    qtGroupRowCol.append(",");
                    qtGroupRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                    qtGroupRowCol.append(key);
                    qtGroupRowCol.append(" ELSE '' END) ");
                    qtOrderRowCol.append(",");
                    qtOrderRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                    qtOrderRowCol.append(key);
                    qtOrderRowCol.append(" ELSE '' END) ASC");
                } else {
                    qtRowCol.append(",");
                    qtRowCol.append("DECODE(A.LEAF, 1, ");
                    qtRowCol.append(key);
                    qtRowCol.append(", NULL) ");
                    qtRowCol.append(key);
                    qtGroupRowCol.append(",");
                    qtGroupRowCol.append("DECODE(A.LEAF, 1, ");
                    qtGroupRowCol.append(key);
                    qtGroupRowCol.append(", NULL) ");
                    qtOrderRowCol.append(",");
                    qtOrderRowCol.append("DECODE(A.LEAF, 1, ");
                    qtOrderRowCol.append(key);
                    qtOrderRowCol.append(", NULL) DESC");
                }

                rowCol.append(", ");
                rowCol.append(key);
                if (i == 0) {
                    wdIsNullCon.append(key);
                    wdIsNullCon.append(" IS NULL");
                    wdIsNotNullCon.append(key);
                    wdIsNotNullCon.append(" IS NOT NULL");
                } else {
                    wdIsNullCon.append(" AND ");
                    wdIsNullCon.append(key);
                    wdIsNullCon.append(" IS NULL");
                    wdIsNotNullCon.append(" AND ");
                    wdIsNotNullCon.append(key);
                    wdIsNotNullCon.append(" IS NOT NULL");
                }

                ++i;
                selectRowCol.append(", ");
                if (DBUtil.isMySql()) {
                    selectRowCol.append("MAX(CASE A.DIM_TYPE_ID WHEN '");
                    selectRowCol.append(dimTypeId);
                    selectRowCol.append("' THEN A.DIM_VAL ELSE NULL END) ");
                    selectRowCol.append(key);
                } else {
                    selectRowCol.append("MAX(DECODE(A.DIM_TYPE_ID,'");
                    selectRowCol.append(dimTypeId);
                    selectRowCol.append("',NVL(F.OBJ_ID1,A.DIM_VAL),NULL)) ");
                    selectRowCol.append(key);
                }
            }

            if (StringUtils.isNotEmpty(wdIsNullCon.toString())) {
                rollupRowCon.append("(");
                rollupRowCon.append(wdIsNullCon.toString());
                rollupRowCon.append(") OR (");
                rollupRowCon.append(wdIsNotNullCon.toString());
                rollupRowCon.append(")");
            }
        }



        param.put("colToRowWdCol", selectRowCol.toString());
        param.put("wdCol", rowCol.toString());
        param.put("rollupRowCon", rollupRowCon.toString());
        param.put("qtRowCol", qtRowCol.toString());
        param.put("qtGroupRowCol", qtGroupRowCol.toString());
        param.put("qtOrderRowCol", qtOrderRowCol.toString());
    }

    private void bulidColByWd(Map<String, Object> param, List<Map<String, Object>> wdList) {
        StringBuilder rowCol = new StringBuilder("");
        StringBuilder qtRowCol = new StringBuilder("");
        StringBuilder qtGroupRowCol = new StringBuilder("");
        StringBuilder qtOrderRowCol = new StringBuilder("");
        StringBuffer selectRowCol = new StringBuffer("");
        StringBuilder rollupRowCon = new StringBuilder("");
        String type = "2";
        String wdName = "";
        String lxid = "";
        int i = 0;
        StringBuilder wdIsNullCon = new StringBuilder("");
        StringBuilder wdIsNotNullCon = new StringBuilder("");
        if (!CollectionUtils.isEmpty(wdList)) {
            Iterator var15 = wdList.iterator();

            label70:
            while(true) {
                while(true) {
                    Map map;
                    do {
                        if (!var15.hasNext()) {
                            if (StringUtils.isNotEmpty(wdIsNullCon.toString())) {
                                rollupRowCon.append("(");
                                rollupRowCon.append(wdIsNullCon.toString());
                                rollupRowCon.append(") OR (");
                                rollupRowCon.append(wdIsNotNullCon.toString());
                                rollupRowCon.append(")");
                            }
                            break label70;
                        }

                        map = (Map)var15.next();
                        type = ConvertUtil.toString(map.get("type"));
                    } while("2".equals(type));

                    wdName = ConvertUtil.toString(map.get("wdname"));
                    lxid = ConvertUtil.toString(map.get("lxid"));
                    if (DBUtil.isMySql()) {
                        qtRowCol.append(",");
                        qtRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                        qtRowCol.append(wdName);
                        qtRowCol.append(" ELSE NULL END) ");
                        qtRowCol.append(wdName);
                        qtGroupRowCol.append(",");
                        qtGroupRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                        qtGroupRowCol.append(wdName);
                        qtGroupRowCol.append(" ELSE NULL END) ");
                        qtOrderRowCol.append(",");
                        qtOrderRowCol.append("(CASE A.LEAF WHEN 1 THEN ");
                        qtOrderRowCol.append(wdName);
                        qtOrderRowCol.append(" ELSE NULL END) ASC");
                    } else {
                        qtRowCol.append(",");
                        qtRowCol.append("DECODE(A.LEAF, 1, ");
                        qtRowCol.append(wdName);
                        qtRowCol.append(", NULL) ");
                        qtRowCol.append(wdName);
                        qtGroupRowCol.append(",");
                        qtGroupRowCol.append("DECODE(A.LEAF, 1, ");
                        qtGroupRowCol.append(wdName);
                        qtGroupRowCol.append(", NULL) ");
                        qtOrderRowCol.append(",");
                        qtOrderRowCol.append("DECODE(A.LEAF, 1, ");
                        qtOrderRowCol.append(wdName);
                        qtOrderRowCol.append(", NULL) DESC");
                    }

                    rowCol.append(", ");
                    rowCol.append(wdName);
                    selectRowCol.append(", ");
                    if (i == 0) {
                        wdIsNullCon.append(wdName);
                        wdIsNullCon.append(" IS NULL");
                        wdIsNotNullCon.append(wdName);
                        wdIsNotNullCon.append(" IS NOT NULL");
                    } else {
                        wdIsNullCon.append(" AND ");
                        wdIsNullCon.append(wdName);
                        wdIsNullCon.append(" IS NULL");
                        wdIsNotNullCon.append(" AND ");
                        wdIsNotNullCon.append(wdName);
                        wdIsNotNullCon.append(" IS NOT NULL");
                    }

                    ++i;
                    if (StringUtils.isNotEmpty(lxid) && lxid.contains(",")) {
                        String[] dxids = lxid.split(",");
                        if (DBUtil.isMySql()) {
                            selectRowCol.append("MAX(CASE A.DIM_TYPE_ID ");
                        } else {
                            selectRowCol.append("MAX(");
                        }

                        StringBuilder endS = new StringBuilder("");
                        String[] var19 = dxids;
                        int var20 = dxids.length;

                        for(int var21 = 0; var21 < var20; ++var21) {
                            String s = var19[var21];
                            if (DBUtil.isMySql()) {
                                selectRowCol.append(" WHEN '");
                                selectRowCol.append(s);
                                selectRowCol.append("' THEN A.DIM_VAL ");
                            } else {
                                selectRowCol.append("DECODE(A1.DIM_TYPE_ID,'");
                                selectRowCol.append(s);
                                selectRowCol.append("',NVL(F.OBJ_ID1,A.DIM_VAL),");
                            }

                            endS.append(")");
                        }

                        if (DBUtil.isMySql()) {
                            selectRowCol.append(" ELSE NULL END) ");
                            selectRowCol.append(wdName);
                        } else {
                            selectRowCol.append("NULL");
                            selectRowCol.append(endS.toString().substring(1));
                            selectRowCol.append(",NULL)) ");
                            selectRowCol.append(wdName);
                        }
                    } else if (DBUtil.isMySql()) {
                        selectRowCol.append("MAX(CASE A.DIM_TYPE_ID WHEN '");
                        selectRowCol.append(lxid);
                        selectRowCol.append("' THEN A.DIM_VAL ELSE NULL END) ");
                        selectRowCol.append(wdName);
                    } else {
                        selectRowCol.append("MAX(DECODE(A.DIM_TYPE_ID,'");
                        selectRowCol.append(lxid);
                        selectRowCol.append("',NVL(F.OBJ_ID1,A.DIM_VAL),NULL)) ");
                        selectRowCol.append(wdName);
                    }
                }
            }
        }



        param.put("colToRowWdCol", selectRowCol.toString());
        param.put("wdCol", rowCol.toString());
        param.put("rollupRowCon", rollupRowCon.toString());
        param.put("qtRowCol", qtRowCol.toString());
        param.put("qtGroupRowCol", qtGroupRowCol.toString());
        param.put("qtOrderRowCol", qtOrderRowCol.toString());
    }

    private String buildSqlForKm(Map<String, Object> param) {
        String findSql = "";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        if (StringUtils.isEmpty(dataOption)) {
            findSql = this.buildHzSqlForKm(param);
        } else if ("COLLECTIONDATA".equals(dataOption)) {
            findSql = this.buildHzSqlForKm(param);
        } else if ("MERGEDATA".equals(dataOption)) {
            findSql = this.buildHbSqlForKm(param);
        } else {
            findSql = this.buildOsetSqlForKm(param);
        }

        return findSql;
    }

    private String buildSqlForKmShowAllDim(Map<String, Object> param) {
        String findSql = "";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        if (StringUtils.isEmpty(dataOption)) {
            findSql = this.buildHzSqlForKmShowAllDim(param);
        } else if ("COLLECTIONDATA".equals(dataOption)) {
            findSql = this.buildHzSqlForKmShowAllDim(param);
        } else if (!"MERGEDATA".equals(dataOption)) {
            findSql = this.buildOsetSqlForKmShowAllDim(param);
        }

        return findSql;
    }

    private String buildHzSqlForKmShowAllDim(Map<String, Object> param) {
        String findSql = "";
        String qtyFindSql = "";
        String findSqlShowEmptyDimValue = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("moneyTypeCondition"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        boolean isShowEmptyDimensionValue = ConvertUtil.toBoolean(param.get("isShowEmptyDimensionValue"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = "";
        if (moneyType == -3) {
            allSelectMoney = ",FOR_CUR";
            allMoney = ",FOR_CUR";
        }

        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        String dataTypeCondition = ConvertUtil.toString(param.get("dataTypeCondition"));
        String dataCon = "";
        String rowNum = "";
        if (StringUtils.isNotEmpty(dataTypeCondition)) {
            dataCon = " WHERE " + dataTypeCondition.replaceAll("A\\.", "A1.");
            if (returnCount != 0) {
                if (DBUtil.isMySql()) {
                    if (ConvertUtil.toBoolean(param.get("export"))) {
                        rowNum = " ";
                    } else {
                        rowNum = " LIMIT " + returnCount;
                    }
                } else {
                    rowNum = " AND ROWNUM<=" + returnCount;
                }
            }
        } else if (returnCount != 0) {
            if (DBUtil.isMySql()) {
                if (ConvertUtil.toBoolean(param.get("export"))) {
                    rowNum = " ";
                } else {
                    rowNum = " LIMIT " + returnCount;
                }
            } else {
                rowNum = " WHERE ROWNUM<=" + returnCount;
            }
        }

        StringBuilder fromTable = new StringBuilder("");
        String balTable = "ACC_BAL_DIM_SUM{1}";
        String vTableName = "";
        String compids = " A.FINA_ORG COMP_ID";
        String groupCompid = " A.FINA_ORG ";
        if (!isBottomUnit) {
            balTable = "ACC_BAL_DIM_SUM{1}_TOP";
        }

        boolean isKmWdQuery = ConvertUtil.toBoolean(param.get("isKmWdQuery"));
        String mockData = ConvertUtil.toString(param.get("ACC_GEN_STA_DIM_BAL"));
        if (StringUtils.isNotBlank(mockData) && "1".equals(mockData) && isKmWdQuery) {
            balTable = "ACC_BAL_STA_DIM_SUM{1}";
            if (!isBottomUnit) {
                balTable = "ACC_BAL_STA_DIM_SUM{1}_TOP";
            }
        }

        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            compids = " A.PROF_CEN COMP_ID ";
            groupCompid = " A.PROF_CEN ";
            balTable = "{0}ACC_PFT_BAL_DIM_SUM{1}";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
            if (!isBottomUnit) {
                balTable = "{0}ACC_PFT_BAL_DIM_SUM{1}_TOP";
            }
        }

        vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            fromTable.append("(SELECT " + fileds + " FROM " + vTableName + " T )");
        } else {
            fromTable.append(vTableName);
        }

        fromTable.append(" A ");
        String qtyTable = AccComprehensiveQueryQtySqlDaoConst.getQtyTable(fromTable.toString());
        if (moneyType == -3) {
            rowNum = "";
        }

        StringBuilder fromTableEmptyDV = new StringBuilder("");
        String moneyColShowEmpty;
        String moneyCol;
        String slzSelectCondition;
        if (isShowEmptyDimensionValue) {
            moneyColShowEmpty = "ACC_BAL_SUM{1}";
            moneyCol = "";
            if (!isBottomUnit) {
                moneyColShowEmpty = "ACC_BAL_SUM{1}_TOP";
            }

            slzSelectCondition = null;
            if (StringUtils.isNotEmpty(selectPftCompId)) {
                moneyColShowEmpty = "{0}ACC_PFT_BAL_SUM{1}";
                slzSelectCondition = " T.PROF_CEN FINA_ORG, T.* ";
                if (!isBottomUnit) {
                    moneyColShowEmpty = "{0}ACC_PFT_BAL_SUM{1}_TOP";
                }
            }

            moneyCol = MessageFormat.format(moneyColShowEmpty, "", accountYear);
            if (StringUtils.isNotEmpty(selectPftCompId)) {
                fromTableEmptyDV.append("(SELECT " + slzSelectCondition + " FROM " + moneyCol + " T )");
            } else {
                fromTableEmptyDV.append(moneyCol);
            }

            fromTableEmptyDV.append(" A ");
        }

        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                if (moneyType == -3) {
                    param.put("allMoneyRownum", rowNum);
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, compids, groupCompid, "", "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_MONTH, qtyTable, beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, compids, groupCompid, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN A.CR_BALP_S - A.DR_BALP_S ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END) SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.CR_BALP_S) * -1 ELSE A.CR_BALP_E END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.CR_BALP_S) * -1 ELSE A.CR_BALP_E END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.DR_BALP_S) * -1 ELSE A.DR_BALP_E END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.DR_BALP_S) * -1 ELSE A.DR_BALP_E END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_BALP_E - A.DR_BALP_E ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_BALP_E - A.DR_BALP_E ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_AMT_Y ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_AMT_Y ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_AMT_Y ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_AMT_Y ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (isShowEmptyDimensionValue) {
                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_MONTH_SHOW_EMPTY, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, compids, groupCompid, fromTableEmptyDV.toString());
                }

                if (isForCur == 1) {
                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "", "", "");
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, qtyTable, beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)  SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)  SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\t\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        param.put("qtyFindSql", qtyFindSql);
                    }

                    if (isShowEmptyDimensionValue) {
                        findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, compids, groupCompid, fromTableEmptyDV.toString(), allMoney, allSelectMoney);
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allMoney = ",-3 FOR_CUR";
                        moneyColShowEmpty = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "", "", "");
                        findSql = findSql + " UNION ALL " + moneyColShowEmpty;
                        if (isShowEmptyDimensionValue) {
                            moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, compids, groupCompid, fromTableEmptyDV.toString(), allMoney, allSelectMoney);
                            findSqlShowEmptyDimValue = findSqlShowEmptyDimValue + " UNION ALL " + moneyCol;
                        }

                        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                            moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, qtyTable, beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)  SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)  SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\t\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                            qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                            param.put("qtyFindSql", qtyFindSql);
                        }
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                slzSelectCondition = "\t       ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y)) QCYE_SL, \n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y)) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y))  /  SUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y))\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) \n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                    slzSelectCondition = "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(A.CR_QTY_S - A.DR_QTY_S) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_S - A.DR_QTY_S) <> 0 THEN SUM(A.CR_BALP_S - A.DR_BALP_S) /  SUM(A.CR_QTY_S - A.DR_QTY_S)\n\t\t\t   ELSE SUM(A.CR_BALP_S - A.DR_BALP_S)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.DR_QTY_TOT) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_TOT) <> 0 THEN SUM(A.DR_AMT_TOT) /  SUM(A.DR_QTY_TOT)\n\t\t\t   ELSE SUM(A.DR_AMT_TOT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_TOT) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_TOT) <> 0 THEN SUM(A.CR_AMT_TOT) /  SUM(A.CR_QTY_TOT)\n\t\t\t   ELSE SUM(A.CR_AMT_TOT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, "", "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (isShowEmptyDimensionValue) {
                    moneyColShowEmpty = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) * -1 QCYE_BWB, SUM(A.CR_AMT_Y) * -1 SUM_J_BWB, SUM(A.DR_AMT_Y) * -1 SUM_D_BWB";
                    if (isSameAccount == 1) {
                        moneyColShowEmpty = "SUM(A.CR_BALP_S - A.DR_BALP_S) * -1 QCYE_BWB, SUM(A.DR_AMT_TOT) * -1 SUM_J_BWB, SUM(A.CR_AMT_TOT) * -1 SUM_D_BWB";
                    }

                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, fromTableEmptyDV.toString(), moneyColShowEmpty);
                }

                if (isForCur == 1) {
                    slzSelectCondition = ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t        \n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL,\n\t\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)  <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) \n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\n\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) \n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        slzSelectCondition = ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    if (moneyType == -3) {
                        param.put("allMoneyRownum", rowNum);
                        rowNum = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "", "", "");
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        param.put("qtyFindSql", qtyFindSql);
                    }

                    moneyColShowEmpty = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) * -1 SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyColShowEmpty = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) * -1 SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyColShowEmpty = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) * -1 SUM_D_BWB";
                        if (DBUtil.isMySql()) {
                            moneyColShowEmpty = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) * -1 SUM_D_BWB";
                        }
                    }

                    if (isShowEmptyDimensionValue) {
                        findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, fromTableEmptyDV.toString(), moneyColShowEmpty, kmAndAccJoin, allMoney, allSelectMoney);
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allMoney = ",-3 FOR_CUR";
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "", "", "");
                        findSql = findSql + " UNION ALL " + allSql;
                        String qtyAllSql;
                        if (isShowEmptyDimensionValue) {
                            qtyAllSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, fromTableEmptyDV.toString(), moneyColShowEmpty, kmAndAccJoin, allMoney, allSelectMoney);
                            findSqlShowEmptyDimValue = findSqlShowEmptyDimValue + " UNION ALL " + qtyAllSql;
                        }

                        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                            qtyAllSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                            qtyFindSql = qtyFindSql + " UNION ALL " + qtyAllSql;
                            param.put("qtyFindSql", qtyFindSql);
                        }
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_MONTH, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "", "", "");
            if (isShowEmptyDimensionValue) {
                findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_MONTH_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, fromTableEmptyDV.toString());
            }

            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_MONTH, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(A.CR_QTY_S - A.DR_QTY_S) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_S - A.DR_QTY_S) <> 0 THEN SUM(A.CR_BALP_S - A.DR_BALP_S) /  SUM(A.CR_QTY_S - A.DR_QTY_S)\n\t\t\t   ELSE SUM(A.CR_BALP_S - A.DR_BALP_S)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.DR_QTY_TOT) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_TOT) <> 0 THEN SUM(A.DR_AMT_TOT) /  SUM(A.DR_QTY_TOT)\n\t\t\t   ELSE SUM(A.DR_AMT_TOT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_TOT) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_TOT) <> 0 THEN SUM(A.CR_AMT_TOT) /  SUM(A.CR_QTY_TOT)\n\t\t\t   ELSE SUM(A.CR_AMT_TOT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                if (isShowEmptyDimensionValue) {
                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, fromTableEmptyDV.toString(), allMoney, allSelectMoney);
                }

                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_MONTH_FOR_CUR, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allMoney = ",-3 FOR_CUR";
                    moneyColShowEmpty = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                    findSql = findSql + " UNION ALL " + moneyColShowEmpty;
                    if (isShowEmptyDimensionValue) {
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, fromTableEmptyDV.toString(), allMoney, allSelectMoney);
                        findSqlShowEmptyDimValue = findSqlShowEmptyDimValue + " UNION ALL " + moneyCol;
                    }

                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_MONTH_FOR_CUR, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_QUARTER, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "", "", "");
            if (isShowEmptyDimensionValue) {
                findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_QUARTER_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, fromTableEmptyDV.toString());
            }

            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_QUARTER, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\t SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.SE_DE_AMOUNT- A.DR_BALP_E + A.SE_CR_AMOUNT) /   SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.SE_DE_AMOUNT- A.DR_BALP_E + A.SE_CR_AMOUNT)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.SE_DE_QTY) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.SE_DE_QTY) <> 0 THEN SUM(A.SE_DE_AMOUNT) /  SUM(A.SE_DE_QTY)\n\t\t\t   ELSE SUM(A.SE_DE_AMOUNT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.SE_CR_QTY) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.SE_CR_QTY) <> 0 THEN SUM(A.SE_CR_AMOUNT) /  SUM(A.SE_CR_QTY)\n\t\t\t   ELSE SUM(A.SE_CR_AMOUNT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /   SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX\t", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                if (isShowEmptyDimensionValue) {
                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_QUARTER_FOR_CUR_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, fromTableEmptyDV.toString(), allMoney, allSelectMoney);
                }

                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE, \n\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END) /   SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allMoney = ",-3 FOR_CUR";
                    rowNum = "";
                    moneyColShowEmpty = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                    findSql = findSql + " UNION ALL " + moneyColShowEmpty;
                    if (isShowEmptyDimensionValue) {
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_QUARTER_FOR_CUR_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, fromTableEmptyDV.toString(), allMoney, allSelectMoney);
                        findSqlShowEmptyDimValue = findSqlShowEmptyDimValue + " UNION ALL " + moneyCol;
                    }

                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE, \n\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END) /   SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyColShowEmpty = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, "", "", "");
            if (isShowEmptyDimensionValue) {
                findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, fromTableEmptyDV.toString(), moneyColShowEmpty);
            }

            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM( A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y) /   SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y )\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /   SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                moneyColShowEmpty = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) * -1 SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    moneyColShowEmpty = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) * -1 SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "", "", "");
                if (isShowEmptyDimensionValue) {
                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, fromTableEmptyDV.toString(), moneyColShowEmpty, kmAndAccJoin, allMoney, allSelectMoney);
                }

                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allMoney = ",-3 FOR_CUR";
                    rowNum = "";
                    slzSelectCondition = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "", "", "");
                    findSql = findSql + " UNION ALL " + slzSelectCondition;
                    if (isShowEmptyDimensionValue) {
                        moneyColShowEmpty = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, fromTableEmptyDV.toString(), moneyColShowEmpty, kmAndAccJoin, allMoney, allSelectMoney);
                        findSqlShowEmptyDimValue = findSqlShowEmptyDimValue + " UNION ALL " + moneyColShowEmpty;
                    }

                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        moneyColShowEmpty = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, compids, groupCompid, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + moneyColShowEmpty;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        }

        param.put("findSqlShowEmptyDimValue", findSqlShowEmptyDimValue);
        return findSql;
    }

    private String buildHzSqlForKm(Map<String, Object> param) {
        String findSql = "";
        String qtyFindSql = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("moneyTypeCondition"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = "";
        if (moneyType == -3) {
            allSelectMoney = ",FOR_CUR";
            allMoney = ",FOR_CUR";
        }

        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        String dataTypeCondition = ConvertUtil.toString(param.get("dataTypeCondition"));
        String dataCon = "";
        String rowNum = "";
        if (StringUtils.isNotEmpty(dataTypeCondition)) {
            dataCon = " WHERE " + dataTypeCondition.replaceAll("A\\.", "A1.");
            if (returnCount != 0) {
                if (DBUtil.isMySql()) {
                    if (ConvertUtil.toBoolean(param.get("export"))) {
                        rowNum = " ";
                    } else {
                        (new StringBuilder()).append(" LIMIT ").append(returnCount).toString();
                    }
                } else {
                    (new StringBuilder()).append(" AND ROWNUM<=").append(returnCount).toString();
                }
            }
        } else if (returnCount != 0) {
            if (DBUtil.isMySql()) {
                if (ConvertUtil.toBoolean(param.get("export"))) {
                    rowNum = " ";
                } else {
                    (new StringBuilder()).append(" LIMIT ").append(returnCount).toString();
                }
            } else {
                (new StringBuilder()).append(" WHERE ROWNUM<=").append(returnCount).toString();
            }
        }

        rowNum = "";
        StringBuilder fromTable = new StringBuilder("");
        String balTable = "ACC_BAL_SUM{1}";
        if (!isBottomUnit) {
            balTable = "ACC_BAL_SUM{1}_TOP";
        }

        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_SUM{1}";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
            if (!isBottomUnit) {
                balTable = "{0}ACC_PFT_BAL_SUM{1}_TOP";
            }
        }

        String vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            fromTable.append("(SELECT " + fileds + " FROM " + vTableName + " T )");
        } else {
            fromTable.append(vTableName);
        }

        fromTable.append(" A ");
        String qtyTable = AccComprehensiveQueryQtySqlDaoConst.getQtyTable(fromTable.toString());
        if (moneyType == -3) {
            rowNum = "";
        }

        String moneyCol;
        String slzSelectCondition;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "", "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_MONTH, qtyTable, beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN A.CR_BALP_S - A.DR_BALP_S ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END) SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.CR_BALP_S) * -1 ELSE A.CR_BALP_E END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.CR_BALP_S) * -1 ELSE A.CR_BALP_E END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.DR_BALP_S) * -1 ELSE A.DR_BALP_E END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.DR_BALP_S) * -1 ELSE A.DR_BALP_E END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_BALP_E - A.DR_BALP_E ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_BALP_E - A.DR_BALP_E ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_AMT_Y ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_AMT_Y ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_AMT_Y ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_AMT_Y ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (isForCur == 1) {
                    if (moneyType == -3) {
                        rowNum = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_MONTH_FOR_CUR, qtyTable, beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)  SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)  SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\t\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        param.put("qtyFindSql", qtyFindSql);
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allMoney = ",-3 FOR_CUR";
                        rowNum = "";
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                        findSql = findSql + " UNION ALL " + moneyCol;
                        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                            moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_MONTH_FOR_CUR, qtyTable, beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)  SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)  SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\t\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                            qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                            param.put("qtyFindSql", qtyFindSql);
                        }
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                slzSelectCondition = "\t       ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y)) QCYE_SL, \n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y)) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y))  /  SUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y))\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) \n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                    slzSelectCondition = "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(A.CR_QTY_S - A.DR_QTY_S) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_S - A.DR_QTY_S) <> 0 THEN SUM(A.CR_BALP_S - A.DR_BALP_S) /  SUM(A.CR_QTY_S - A.DR_QTY_S)\n\t\t\t   ELSE SUM(A.CR_BALP_S - A.DR_BALP_S)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.DR_QTY_TOT) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_TOT) <> 0 THEN SUM(A.DR_AMT_TOT) /  SUM(A.DR_QTY_TOT)\n\t\t\t   ELSE SUM(A.DR_AMT_TOT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_TOT) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_TOT) <> 0 THEN SUM(A.CR_AMT_TOT) /  SUM(A.CR_QTY_TOT)\n\t\t\t   ELSE SUM(A.CR_AMT_TOT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, "", "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (isForCur == 1) {
                    slzSelectCondition = ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t        \n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL,\n\t\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)  <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) \n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\n\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) \n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        slzSelectCondition = ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    if (moneyType == -3) {
                        rowNum = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        param.put("qtyFindSql", qtyFindSql);
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allMoney = ",-3 FOR_CUR";
                        rowNum = "";
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, "", "", "", "");
                        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                            String qtyAllSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                            qtyFindSql = qtyFindSql + " UNION ALL " + qtyAllSql;
                            param.put("qtyFindSql", qtyFindSql);
                        }

                        findSql = findSql + " UNION ALL " + allSql;
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_MONTH, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "", "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_MONTH, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(A.CR_QTY_S - A.DR_QTY_S) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_S - A.DR_QTY_S) <> 0 THEN SUM(A.CR_BALP_S - A.DR_BALP_S) /  SUM(A.CR_QTY_S - A.DR_QTY_S)\n\t\t\t   ELSE SUM(A.CR_BALP_S - A.DR_BALP_S)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.DR_QTY_TOT) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_TOT) <> 0 THEN SUM(A.DR_AMT_TOT) /  SUM(A.DR_QTY_TOT)\n\t\t\t   ELSE SUM(A.DR_AMT_TOT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_TOT) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_TOT) <> 0 THEN SUM(A.CR_AMT_TOT) /  SUM(A.CR_QTY_TOT)\n\t\t\t   ELSE SUM(A.CR_AMT_TOT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_MONTH_FOR_CUR, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allMoney = ",-3 FOR_CUR";
                    rowNum = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                    findSql = findSql + " UNION ALL " + moneyCol;
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_MONTH_FOR_CUR, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_QUARTER, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "", "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_QUARTER, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\t SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.SE_DE_AMOUNT- A.DR_BALP_E + A.SE_CR_AMOUNT) /   SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.SE_DE_AMOUNT- A.DR_BALP_E + A.SE_CR_AMOUNT)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.SE_DE_QTY) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.SE_DE_QTY) <> 0 THEN SUM(A.SE_DE_AMOUNT) /  SUM(A.SE_DE_QTY)\n\t\t\t   ELSE SUM(A.SE_DE_AMOUNT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.SE_CR_QTY) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.SE_CR_QTY) <> 0 THEN SUM(A.SE_CR_AMOUNT) /  SUM(A.SE_CR_QTY)\n\t\t\t   ELSE SUM(A.SE_CR_AMOUNT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /   SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX\t", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_QUARTER_FOR_CUR, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE, \n\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END) /   SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allMoney = ",-3 FOR_CUR";
                    allSelectMoney = "";
                    rowNum = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                    findSql = findSql + " UNION ALL " + moneyCol;
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_BY_QUARTER_FOR_CUR, qtyTable, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE, \n\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END) /   SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, "", "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM( A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y) /   SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y )\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /   SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                }

                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allMoney = ",-3 FOR_CUR";
                    rowNum = "";
                    allSelectMoney = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "", "", "");
                    findSql = findSql + " UNION ALL " + moneyCol;
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        slzSelectCondition = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "\t       ,A1.MEASUR_UNIT,A1.MEAS_UNIT_GROUP_CODE, \n\t       A1.QCYE_SL,A1.QCYE_DJ,\n\t       A1.SUM_J_SL,A1.SUM_J_DJ,\n\t       A1.SUM_D_SL,A1.SUM_D_DJ,\n\t       A1.QMYE_SL,A1.QMYE_DJ,\n\t       A1.SUM_JL_SL,A1.SUM_JL_DJ,\n\t       A1.SUM_DL_SL,A1.SUM_DL_DJ,\n\t       BZLX", ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + slzSelectCondition;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        }

        AccComprehensiveQueryConvertSqlDao.unionConcatSql(findSql, param);
        return findSql;
    }

    private String buildHbSqlForKm(Map<String, Object> param) {
        String findSql = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("moneyTypeCondition"));
        String osetCompidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
        String osetMoneyTypeOption = ConvertUtil.toString(param.get("osetMoneyTypeOption"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        String dataTypeCondition = ConvertUtil.toString(param.get("dataTypeCondition"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = "";
        if (moneyType == -3) {
            allSelectMoney = ",FOR_CUR";
            allMoney = ",FOR_CUR";
        }

        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        String dataCon = "";
        String rowNum = "";
        if (StringUtils.isNotEmpty(dataTypeCondition)) {
            dataCon = " WHERE " + dataTypeCondition.replaceAll("A\\.", "A1.");
            if (returnCount != 0) {
                if (DBUtil.isMySql()) {
                    if (ConvertUtil.toBoolean(param.get("export"))) {
                        rowNum = " ";
                    } else {
                        rowNum = " LIMIT " + returnCount;
                    }
                } else {
                    rowNum = " AND ROWNUM<=" + returnCount;
                }
            }
        } else if (returnCount != 0) {
            if (DBUtil.isMySql()) {
                if (ConvertUtil.toBoolean(param.get("export"))) {
                    rowNum = " ";
                } else {
                    rowNum = " LIMIT " + returnCount;
                }
            } else {
                rowNum = " WHERE ROWNUM<=" + returnCount;
            }
        }

        StringBuilder fromTable = new StringBuilder("");
        StringBuilder fromOsetTable = new StringBuilder("");
        String balTable = "ACC_BAL_SUM{1}";
        String vTableName = "";
        if (!isBottomUnit) {
            balTable = "ACC_BAL_SUM{1}_TOP";
        }

        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_SUM{1}";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
            if (!isBottomUnit) {
                balTable = "{0}ACC_PFT_BAL_SUM{1}_TOP";
            }
        }

        vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            fromTable.append("(SELECT " + fileds + " FROM " + vTableName + " T )");
        } else {
            fromTable.append(vTableName);
        }

        fromTable.append(" A ");
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        if (mxdwQuery != null && mxdwQuery == 1) {
            fromOsetTable.append(MessageFormat.format("OSET_BAL_SUM{1}", "", accountYear));
        } else {
            fromOsetTable.append(MessageFormat.format("OSET_BAL_SUM{1}_TOP", "", accountYear));
        }

        fromOsetTable.append(" A ");
        boolean ismxdwQuery = mxdwQuery != null && mxdwQuery == 1;
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String bzlx = "";
        String hzBzlx = "";
        String dxBzlx = "";
        if ("MERGEDATA".equals(dataOption) && ismxdwQuery) {
            bzlx = " ,bzlx ";
            hzBzlx = " , 0 bzlx ";
            dxBzlx = " , 1 bzlx ";
        }

        if (moneyType == -3) {
            rowNum = "";
        }

        String moneyCol;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, accoStatusContion, bzlx, hzBzlx, dxBzlx);
                if (isForCur == 1) {
                    if (moneyType == -3) {
                        rowNum = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        osetMoneyTypeOption = "AND A.STA_CUR =1";
                        allSelectMoney = ",-3 FOR_CUR";
                        rowNum = "";
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                        findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + moneyCol + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB".replaceAll("A\\.", "D.");
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB".replaceAll("A\\.", "D.");
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, bzlx, hzBzlx, dxBzlx);
                if (isForCur == 1) {
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB".replaceAll("A\\.", "D.");
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB".replaceAll("A\\.", "D.");
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB".replaceAll("A\\.", "D.");
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB".replaceAll("A\\.", "D.");
                        }
                    }

                    if (moneyType == -3) {
                        osetMoneyTypeOption = "";
                        rowNum = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        osetMoneyTypeOption = "AND A.STA_CUR =1";
                        allSelectMoney = ",-3 FOR_CUR";
                        rowNum = "";
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                        findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + allSql + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_BY_MONTH, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, accoStatusContion, bzlx, hzBzlx, dxBzlx);
            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    osetMoneyTypeOption = "AND A.STA_CUR =1";
                    allSelectMoney = ",-3 FOR_CUR";
                    rowNum = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                    findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + moneyCol + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_BY_QUARTER, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, accoStatusContion, bzlx, hzBzlx, dxBzlx);
            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    osetMoneyTypeOption = "AND A.STA_CUR =1";
                    allSelectMoney = ",-3 FOR_CUR";
                    rowNum = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                    findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + moneyCol + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB".replaceAll("A\\.", "D.");
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, bzlx, hzBzlx, dxBzlx);
            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB".replaceAll("A\\.", "D.");
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB".replaceAll("A\\.", "D.");
                }

                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    osetMoneyTypeOption = "AND A.STA_CUR =1";
                    allSelectMoney = ",-3 FOR_CUR";
                    rowNum = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, dataCon, rowNum, kmAndAccJoin, moneyCol, accoStatusContion, bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney);
                    findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + moneyCol + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                }
            }
        }

        if (mxdwQuery != null && mxdwQuery == 1 && findSql.contains("A.DATA_TYPE = 1")) {
            findSql = findSql.replace("A.DATA_TYPE = 1", "A.DATA_TYPE = 0");
        }

        return findSql;
    }

    private String buildOsetSqlForKm(Map<String, Object> param) {
        String findSql = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("osetMoneyTypeOption"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = "";
        if (moneyType == -3) {
            allSelectMoney = ",FOR_CUR";
            allMoney = ",FOR_CUR";
        }

        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        String dataTypeCondition = ConvertUtil.toString(param.get("dataTypeCondition"));
        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        String dataCon = "";
        String rowNum = "";
        if (StringUtils.isNotEmpty(dataTypeCondition)) {
            dataCon = " WHERE " + dataTypeCondition.replaceAll("A\\.", "A1.");
            if (returnCount != 0) {
                if (DBUtil.isMySql()) {
                    if (ConvertUtil.toBoolean(param.get("export"))) {
                        rowNum = " ";
                    } else {
                        rowNum = " LIMIT " + returnCount;
                    }
                } else {
                    rowNum = " AND ROWNUM<=" + returnCount;
                }
            }
        } else if (returnCount != 0) {
            if (DBUtil.isMySql()) {
                if (ConvertUtil.toBoolean(param.get("export"))) {
                    rowNum = " ";
                } else {
                    rowNum = " LIMIT " + returnCount;
                }
            } else {
                rowNum = " WHERE ROWNUM<=" + returnCount;
            }
        }

        String osetTypeCom = "";
        String balTable = "";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        if ("CONTRADATA1".equals(dataOption)) {
            osetTypeCom = " AND A.DATA_TYPE = 1 ";
            balTable = "OSET_BAL_SUM{1}_TOP";
        } else {
            osetTypeCom = " AND A.DATA_TYPE = 0 ";
            balTable = "OSET_BAL_SUM{1}";
        }

        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        if (mxdwQuery != null && mxdwQuery == 1) {
            osetTypeCom = " AND A.DATA_TYPE = 0 ";
            balTable = "OSET_BAL_SUM{1}";
        }

        StringBuilder fromTable = new StringBuilder("");
        String vTableName = "";
        vTableName = MessageFormat.format(balTable, "", accountYear);
        fromTable.append(vTableName);
        fromTable.append(" A ");
        if (moneyType == -3) {
            rowNum = "";
        }

        String moneyCol;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin);
                if (isForCur == 1) {
                    if (moneyType == -3) {
                        rowNum = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allSelectMoney = ",-3 FOR_CUR";
                        rowNum = "";
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                        findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + moneyCol + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol);
                if (isForCur == 1) {
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    if (moneyType == -3) {
                        rowNum = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allSelectMoney = ",-3 FOR_CUR";
                        rowNum = "";
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, allMoney, allSelectMoney);
                        findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + allSql + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_BY_MONTH, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin);
            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allSelectMoney = ",-3 FOR_CUR";
                    rowNum = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                    findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + moneyCol + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_BY_QUARTER, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin);
            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allSelectMoney = ",-3 FOR_CUR";
                    rowNum = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                    findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + moneyCol + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol);
            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                }

                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allSelectMoney = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, allMoney, allSelectMoney);
                    findSql = " WITH TEMP AS ( " + findSql + " ) ,  TEMP1 AS ( " + moneyCol + " ) SELECT * FROM TEMP UNION ALL SELECT * FROM TEMP1 ";
                }
            }
        }

        return findSql;
    }

    private String buildOsetSqlForKmShowAllDim(Map<String, Object> param) {
        String findSql = "";
        String findSqlShowEmptyDimValue = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("osetMoneyTypeOption"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        int returnCount = ConvertUtil.toInt(param.get("returnCount"));
        String dataTypeCondition = ConvertUtil.toString(param.get("dataTypeCondition"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = "";
        if (moneyType == -3) {
            allSelectMoney = ",FOR_CUR";
            allMoney = ",FOR_CUR";
        }

        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        String dataCon = "";
        String rowNum = "";
        if (StringUtils.isNotEmpty(dataTypeCondition)) {
            dataCon = " WHERE " + dataTypeCondition.replaceAll("A\\.", "A1.");
            if (returnCount != 0) {
                if (DBUtil.isMySql()) {
                    if (ConvertUtil.toBoolean(param.get("export"))) {
                        rowNum = " ";
                    } else {
                        rowNum = " LIMIT " + returnCount;
                    }
                } else {
                    rowNum = " AND ROWNUM<=" + returnCount;
                }
            }
        } else if (returnCount != 0) {
            if (DBUtil.isMySql()) {
                if (ConvertUtil.toBoolean(param.get("export"))) {
                    rowNum = " ";
                } else {
                    rowNum = " LIMIT " + returnCount;
                }
            } else {
                rowNum = " WHERE ROWNUM<=" + returnCount;
            }
        }

        String osetTypeCom = "";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String balTable = "ACC_BAL_DIM_SUM{1}";
        if (!StringUtils.equals("COLLECTIONDATA", dataOption)) {
            if ("CONTRADATA1".equals(dataOption)) {
                osetTypeCom = " AND A.DATA_TYPE = 1 ";
                balTable = "OSET_BAL_DIM_SUM{1}_TOP";
            } else {
                osetTypeCom = " AND A.DATA_TYPE = 0 ";
                balTable = "OSET_BAL_DIM_SUM{1}";
            }
        }

        StringBuffer fromTable = new StringBuffer("");
        String vTableName = "";
        vTableName = MessageFormat.format(balTable, "", accountYear);
        fromTable.append(vTableName);
        fromTable.append(" A ");
        if (moneyType == -3) {
            rowNum = "";
        }

        boolean isShowEmptyDimensionValue = ConvertUtil.toBoolean(param.get("isShowEmptyDimensionValue"));
        StringBuilder fromTableEmptyDV = new StringBuilder("");
        String moneyCol;
        if (isShowEmptyDimensionValue) {
            moneyCol = "ACC_BAL_SUM{1}";
            if (!StringUtils.equals("COLLECTIONDATA", dataOption)) {
                if ("CONTRADATA1".equals(dataOption)) {
                    moneyCol = "OSET_BAL_SUM{1}_TOP";
                } else {
                    moneyCol = "OSET_BAL_SUM{1}";
                }
            }

            moneyCol = "";
            moneyCol = MessageFormat.format(moneyCol, "", accountYear);
            fromTableEmptyDV.append(moneyCol);
            fromTableEmptyDV.append(" A ");
        }

        String moneyColShowEmpty;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                if (moneyType == -3) {
                    param.put("allMoneyRownum", rowNum);
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin);
                if (isShowEmptyDimensionValue) {
                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_MONTH_SHOW_EMPTY, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, fromTableEmptyDV.toString());
                }

                if (isForCur == 1) {
                    if (moneyType == -3) {
                        moneyTypeCondition = "";
                        rowNum = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                    if (isShowEmptyDimensionValue) {
                        findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, fromTableEmptyDV.toString());
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allMoney = ",-3 FOR_CUR";
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                        findSql = findSql + " UNION ALL " + moneyCol;
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol);
                if (isShowEmptyDimensionValue) {
                    moneyColShowEmpty = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) * -1 QCYE_BWB, SUM(A.CR_AMT_Y) * -1 SUM_J_BWB, SUM(A.DR_AMT_Y) * -1 SUM_D_BWB";
                    if (isSameAccount == 1) {
                        moneyColShowEmpty = "SUM(A.CR_BALP_S - A.DR_BALP_S) * -1 QCYE_BWB, SUM(A.DR_AMT_TOT) * -1 SUM_J_BWB, SUM(A.CR_AMT_TOT) * -1 SUM_D_BWB";
                    }

                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, fromTableEmptyDV.toString(), moneyColShowEmpty);
                }

                if (isForCur == 1) {
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = "";
                        param.put("allMoneyRownum", rowNum);
                        rowNum = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, allMoney, allSelectMoney);
                    if (isShowEmptyDimensionValue) {
                        moneyColShowEmpty = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) * -1 SUM_D_BWB";
                        if (DBUtil.isMySql()) {
                            moneyColShowEmpty = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) * -1 SUM_D_BWB";
                        }

                        if (isSameAccount == 1) {
                            moneyColShowEmpty = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) * -1 SUM_D_BWB";
                            if (DBUtil.isMySql()) {
                                moneyColShowEmpty = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) * -1 SUM_D_BWB";
                            }
                        }

                        findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, fromTableEmptyDV.toString(), moneyColShowEmpty);
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allMoney = ",-3 FOR_CUR";
                        moneyColShowEmpty = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, allMoney, allSelectMoney);
                        findSql = findSql + " UNION ALL " + moneyColShowEmpty;
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_MONTH, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin);
            if (isShowEmptyDimensionValue) {
                findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_MONTH_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, fromTableEmptyDV.toString());
            }

            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                if (isShowEmptyDimensionValue) {
                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, fromTableEmptyDV.toString());
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allMoney = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_QUARTER, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin);
            if (isShowEmptyDimensionValue) {
                findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_QUARTER_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, fromTableEmptyDV.toString());
            }

            if (isForCur == 1) {
                if (moneyType == -3) {
                    rowNum = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                if (isShowEmptyDimensionValue) {
                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_QUARTER_FOR_CUR_SHOW_EMPTY, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, fromTableEmptyDV.toString());
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allMoney = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, allMoney, allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) * -1 QCYE_BWB, SUM(A.CR_AMT_Y) * -1 SUM_J_BWB, SUM(A.DR_AMT_Y) * -1 SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol);
            if (isShowEmptyDimensionValue) {
                findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, fromTableEmptyDV.toString(), moneyCol);
            }

            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y ELSE 0 END) SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y ELSE 0 END) SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, allMoney, allSelectMoney);
                if (isShowEmptyDimensionValue) {
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y, 0)) * -1 QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E -  A.CR_AMT_Y + A.DR_AMT_Y)) * -1 QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) * -1 SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) * -1 SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) * -1 SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) * -1 SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) * -1 QCYE, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) * -1 QCYE_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y ELSE 0 END) * -1 SUM_J, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) * -1 SUM_J_BWB, SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y ELSE 0 END) * -1 SUM_D, SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) * -1 SUM_D_BWB";
                    }

                    findSqlShowEmptyDimValue = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR_SHOW_EMPTY, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, fromTableEmptyDV.toString(), moneyCol);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allMoney = ",-3 FOR_CUR";
                    moneyColShowEmpty = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_KM_SHOW_ALL_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, dataCon, rowNum, kmAndAccJoin, moneyCol, allMoney, allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyColShowEmpty;
                }
            }
        }

        param.put("findSqlShowEmptyDimValue", findSqlShowEmptyDimValue);
        return findSql;
    }

    private String buildSqlForOneDim(Map<String, Object> param) {
        String findSql = "";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        if (StringUtils.isEmpty(dataOption)) {
            findSql = this.buildHzSqlForOneDim(param);
        } else if ("COLLECTIONDATA".equals(dataOption)) {
            findSql = this.buildHzSqlForOneDim(param);
        } else if ("MERGEDATA".equals(dataOption)) {
            findSql = this.buildHbSqlForOneDim(param);
        } else {
            findSql = this.buildOsetSqlForOneDim(param);
        }

        return findSql;
    }

    private String buildSqlForDim(Map<String, Object> param) {
        String findSql = "";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        if (StringUtils.isEmpty(dataOption)) {
            findSql = this.buildHzSqlForDim(param);
        } else if ("COLLECTIONDATA".equals(dataOption)) {
            findSql = this.buildHzSqlForDim(param);
        } else if ("MERGEDATA".equals(dataOption)) {
            findSql = this.buildHbSqlForDim(param);
        } else {
            findSql = this.buildOsetSqlForDim(param);
        }

        return findSql;
    }

    private String buildHzSqlForOneDim(Map<String, Object> param) {
        String findSql = "";
        String qtyFindSql = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("moneyTypeCondition"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
        String accoStatus = ConvertUtil.toString(param.get("accoStatus"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        int limitCount = ConvertUtil.toInt(param.get("hzDataLimit"));
        StringBuilder groupByDimGroup = new StringBuilder("");
        int isGroupByDimGroup = ConvertUtil.toInt(param.get("isGroupByDimGroup"));
        Integer oneDimIsCls = ConvertUtil.toInteger(param.get("oneDimIsCls"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        if (isGroupByDimGroup == 1) {
            groupByDimGroup.append(", A.ACC_PERIOD,A.DIM_GROUP");
            if (isForCur == 1) {
                groupByDimGroup.append(",A.STA_CUR");
            }

            if ("0".equals(accoStatus)) {
                groupByDimGroup.append(",A.ENTRY_MARK");
            }
        } else if (Objects.nonNull(oneDimIsCls) && Objects.equals(1, oneDimIsCls)) {
            groupByDimGroup.append(",A.DIM_VAL");
        } else if (DBUtil.isMySql()) {
            groupByDimGroup.append(", A.DIM_VAL ");
        } else if (limitCount > 0) {
            groupByDimGroup.append(", A.DIM_VAL ");
        } else {
            groupByDimGroup.append(",NVL(F.OBJ_ID1, A.DIM_VAL)");
        }

        String kmConditionForSelect = " A.ACC_SUB SUBJECT_ID,";
        String kmConditionForGroupBy = " A.ACC_SUB, ";
        boolean isOneDim = param.get("isYwMainAndOneDim") != null && ConvertUtil.toInt(param.get("isYwMainAndOneDim")) == 1;
        if (isOneDim) {
            kmConditionForSelect = "";
            kmConditionForGroupBy = "";
        }

        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
        String wdCondition = ConvertUtil.toString(param.get("wdCondition"));
        String wdCon = "";
        if (StringUtils.isNotEmpty(wdCondition)) {
            wdCon = " AND (" + wdCondition + ")";
        }

        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        String colToRowWdCol = ConvertUtil.toString(param.get("colToRowWdCol"));
        StringBuilder fromTable = new StringBuilder("");
        String balTable = "ACC_BAL_DIM_ROW{1}";
        String vTableName = "";
        if (!isBottomUnit) {
            balTable = "ACC_BAL_DIM_ROW{1}_TOP";
        }

        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_DIM_ROW{1}";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
            if (!isBottomUnit) {
                balTable = "{0}ACC_PFT_BAL_DIM_ROW{1}_TOP";
            }
        }

        String WDDYKQSQL1 = "";
        String WDDYKQSQL2 = "";
        boolean isKmWdQuery = ConvertUtil.toBoolean(param.get("isKmWdQuery"));
        String mockData = ConvertUtil.toString(param.get("ACC_GEN_STA_DIM_BAL"));
        String qtyTable;
        String slzSelectCondition;
        if (StringUtils.isNotBlank(mockData) && "1".equals(mockData) && (balTable.equals("ACC_BAL_DIM_ROW{1}") || balTable.equals("ACC_BAL_DIM_ROW{1}_TOP")) && isKmWdQuery) {
            qtyTable = ConvertUtil.toString(param.get("compid"));
            List<Map> parentManageCompid = new ArrayList<>();
            slzSelectCondition = (String)parentManageCompid.stream().map((m) -> {
                return "'" + m.get("compid") + "'";
            }).collect(Collectors.joining(","));
            WDDYKQSQL1 = " ,ACC_CAC_DER D";
            WDDYKQSQL2 = " AND A.ACC_SUB = D.ACC_SUB AND A.DIM_CLS = D.DIM_TYPE AND A.DIM_TYPE_ID = D.COR_DIM_TYPE_CODE  AND D.DIM_CAT = 0 AND D.FISC_YEA = " + accountYear + " AND D.ACC_BOOK = " + accbookid + " AND D.CREATE_FINA_ORG IN ( " + slzSelectCondition + " )";
        }

        vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            fromTable.append("(SELECT " + fileds + " FROM " + vTableName + " T )");
        } else {
            fromTable.append(vTableName);
        }

        fromTable.append(" A ");
        qtyTable = AccComprehensiveQueryQtySqlDaoConst.getQtyTable(fromTable.toString());
        if (moneyType == -3) {
            colToRowWdCol = colToRowWdCol + ",A.FOR_CUR";
            groupByDimGroup.append(",A.FOR_CUR");
        }

        String moneyCol;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), accoStatusContion, "", "", WDDYKQSQL1, WDDYKQSQL2);
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_MONTH, qtyTable, beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), accoStatusContion, MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN A.CR_BALP_S - A.DR_BALP_S ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END) SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.CR_BALP_S) * -1 ELSE A.CR_BALP_E END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.CR_BALP_S) * -1 ELSE A.CR_BALP_E END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.DR_BALP_S) * -1 ELSE A.DR_BALP_E END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.DR_BALP_S) * -1 ELSE A.DR_BALP_E END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_BALP_E - A.DR_BALP_E ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_BALP_E - A.DR_BALP_E ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_AMT_Y ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_AMT_Y ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_AMT_Y ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_AMT_Y ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE", WDDYKQSQL1, WDDYKQSQL2);
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (isForCur == 1) {
                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), accoStatusContion, "", "", WDDYKQSQL1, WDDYKQSQL2);
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, qtyTable, beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), accoStatusContion, MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)  SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)  SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\t\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE", WDDYKQSQL1, WDDYKQSQL2);
                        param.put("qtyFindSql", qtyFindSql);
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        colToRowWdCol = colToRowWdCol.replaceAll(",A.FOR_CUR", ",-3 FOR_CUR");
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), accoStatusContion, "", "", WDDYKQSQL1, WDDYKQSQL2);
                        findSql = findSql + " UNION ALL " + moneyCol;
                        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                            slzSelectCondition = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, qtyTable, beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), accoStatusContion, MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)  SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)  SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\t\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE", WDDYKQSQL1, WDDYKQSQL2);
                            qtyFindSql = qtyFindSql + " UNION ALL " + slzSelectCondition;
                            param.put("qtyFindSql", qtyFindSql);
                        }
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                slzSelectCondition = "\t       ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y)) QCYE_SL, \n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y)) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y))  /  SUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y))\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) \n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                    slzSelectCondition = "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(A.CR_QTY_S - A.DR_QTY_S) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_S - A.DR_QTY_S) <> 0 THEN SUM(A.CR_BALP_S - A.DR_BALP_S) /  SUM(A.CR_QTY_S - A.DR_QTY_S)\n\t\t\t   ELSE SUM(A.CR_BALP_S - A.DR_BALP_S)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.DR_QTY_TOT) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_TOT) <> 0 THEN SUM(A.DR_AMT_TOT) /  SUM(A.DR_QTY_TOT)\n\t\t\t   ELSE SUM(A.DR_AMT_TOT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_TOT) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_TOT) <> 0 THEN SUM(A.CR_AMT_TOT) /  SUM(A.CR_QTY_TOT)\n\t\t\t   ELSE SUM(A.CR_AMT_TOT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), moneyCol, accoStatusContion, kmConditionForSelect, kmConditionForGroupBy, "", "", WDDYKQSQL1, WDDYKQSQL2);
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), moneyCol, accoStatusContion, kmConditionForSelect, kmConditionForGroupBy, slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE", WDDYKQSQL1, WDDYKQSQL2);
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (isForCur == 1) {
                    slzSelectCondition = ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t        \n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL,\n\t\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)  <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) \n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\n\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) \n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        slzSelectCondition = ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), moneyCol, accoStatusContion, "", "", WDDYKQSQL1, WDDYKQSQL2);
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), moneyCol, accoStatusContion, slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE", WDDYKQSQL1, WDDYKQSQL2);
                        param.put("qtyFindSql", qtyFindSql);
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        colToRowWdCol = colToRowWdCol.replaceAll(",A.FOR_CUR", ",-3 FOR_CUR");
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), moneyCol, accoStatusContion, "", "", WDDYKQSQL1, WDDYKQSQL2);
                        findSql = findSql + " UNION ALL " + allSql;
                        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                            String qtyAllSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), moneyCol, accoStatusContion, slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE", WDDYKQSQL1, WDDYKQSQL2);
                            qtyFindSql = qtyFindSql + " UNION ALL " + qtyAllSql;
                            param.put("qtyFindSql", qtyFindSql);
                        }
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_MONTH, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), accoStatusContion, "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_MONTH, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), accoStatusContion, "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(A.CR_QTY_S - A.DR_QTY_S) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_S - A.DR_QTY_S) <> 0 THEN SUM(A.CR_BALP_S - A.DR_BALP_S) /  SUM(A.CR_QTY_S - A.DR_QTY_S)\n\t\t\t   ELSE SUM(A.CR_BALP_S - A.DR_BALP_S)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.DR_QTY_TOT) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_TOT) <> 0 THEN SUM(A.DR_AMT_TOT) /  SUM(A.DR_QTY_TOT)\n\t\t\t   ELSE SUM(A.DR_AMT_TOT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_TOT) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_TOT) <> 0 THEN SUM(A.CR_AMT_TOT) /  SUM(A.CR_QTY_TOT)\n\t\t\t   ELSE SUM(A.CR_AMT_TOT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), accoStatusContion, "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_MONTH_FOR_CUR, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), accoStatusContion, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    colToRowWdCol = colToRowWdCol.replaceAll(",A.FOR_CUR", ",-3 FOR_CUR");
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), accoStatusContion, "", "");
                    findSql = findSql + " UNION ALL " + moneyCol;
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        slzSelectCondition = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_MONTH_FOR_CUR, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), accoStatusContion, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + slzSelectCondition;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_QUARTER, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), accoStatusContion, "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_QUARTER, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), accoStatusContion, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\t SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.SE_DE_AMOUNT- A.DR_BALP_E + A.SE_CR_AMOUNT) /   SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.SE_DE_AMOUNT- A.DR_BALP_E + A.SE_CR_AMOUNT)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.SE_DE_QTY) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.SE_DE_QTY) <> 0 THEN SUM(A.SE_DE_AMOUNT) /  SUM(A.SE_DE_QTY)\n\t\t\t   ELSE SUM(A.SE_DE_AMOUNT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.SE_CR_QTY) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.SE_CR_QTY) <> 0 THEN SUM(A.SE_CR_AMOUNT) /  SUM(A.SE_CR_QTY)\n\t\t\t   ELSE SUM(A.SE_CR_AMOUNT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /   SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX\t", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), accoStatusContion, "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), accoStatusContion, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE, \n\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END) /   SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    colToRowWdCol = colToRowWdCol.replaceAll(",A.FOR_CUR", ",-3 FOR_CUR");
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), accoStatusContion, "", "");
                    findSql = findSql + " UNION ALL " + moneyCol;
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        slzSelectCondition = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), accoStatusContion, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE, \n\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END) /   SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + slzSelectCondition;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), moneyCol, accoStatusContion, kmConditionForSelect, kmConditionForGroupBy, "", "", "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), moneyCol, accoStatusContion, kmConditionForSelect, kmConditionForGroupBy, "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM( A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y) /   SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y )\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /   SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE", "", "");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), moneyCol, accoStatusContion, "", "", "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString(), moneyCol, accoStatusContion, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE", "", "");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    colToRowWdCol = colToRowWdCol.replaceAll(",A.FOR_CUR", ",-3 FOR_CUR");
                    slzSelectCondition = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), moneyCol, accoStatusContion, "", "", "", "");
                    findSql = findSql + " UNION ALL " + slzSelectCondition;
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, colToRowWdCol, kmAndAccJoin, groupByDimGroup.toString().replaceAll(",A.FOR_CUR", ""), moneyCol, accoStatusContion, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE", "", "");
                        qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        }

        if (isGroupByDimGroup == 1) {
            if (DBUtil.isMySql()) {
                findSql = findSql.replaceAll("SUM\\(A\\.", "MAX(A.").replaceAll("SUM\\(CASE", "MAX(CASE");
            } else {
                findSql = findSql.replaceAll("SUM\\(A\\.", "MAX(A.").replaceAll("SUM\\(DECODE\\(A\\.", "MAX(DECODE(A.");
            }
        }

        findSql = AccComprehensiveQueryConvertSqlDao.unionConcatSql(findSql, param);
        return findSql;
    }

    private String buildHzSqlForDim(Map<String, Object> param) {
        String findSql = "";
        String qtyFindSql = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("moneyTypeCondition"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        String wdCondition = ConvertUtil.toString(param.get("wdCondition"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = ",A.STA_CUR";
        String allSelectMoney = "";
        String moneyCondition = "";
        if (moneyType == -3) {
            allMoney = ",A.FOR_CUR";
            allSelectMoney = ",A.FOR_CUR";
        }

        String wdCon = "";
        if (StringUtils.isNotEmpty(wdCondition)) {
            wdCon = " AND (" + wdCondition + ")";
        }

        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        StringBuilder fromTable = new StringBuilder("");
        String balTable = "ACC_BAL_DIM_SUM{1}";
        String vTableName = "";
        if (!isBottomUnit) {
            balTable = "ACC_BAL_DIM_SUM{1}_TOP";
        }

        boolean isKmWdQuery = ConvertUtil.toBoolean(param.get("isKmWdQuery"));
        String mockData = ConvertUtil.toString(param.get("ACC_GEN_STA_DIM_BAL"));
        if (StringUtils.isNotBlank(mockData) && "1".equals(mockData) && isKmWdQuery) {
            balTable = "ACC_BAL_STA_DIM_SUM{1}";
            if (!isBottomUnit) {
                balTable = "ACC_BAL_STA_DIM_SUM{1}_TOP";
            }
        }

        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_DIM_SUM{1}";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
            if (!isBottomUnit) {
                balTable = "{0}ACC_PFT_BAL_DIM_SUM{1}_TOP";
            }
        }

        vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            fromTable.append("(SELECT " + fileds + " FROM " + vTableName + " T )");
        } else {
            fromTable.append(vTableName);
        }

        fromTable.append(" A ");
        String qtyTable = AccComprehensiveQueryQtySqlDaoConst.getQtyTable(fromTable.toString());
        String moneyCol;
        String slzSelectCondition;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_MONTH, qtyTable, beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN  A.CR_QTY_S - A.DR_QTY_S  ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN A.CR_BALP_S - A.DR_BALP_S ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END) SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.CR_BALP_S) * -1 ELSE A.CR_BALP_E END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.CR_QTY_S*-1  ELSE A.CR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.CR_BALP_S) * -1 ELSE A.CR_BALP_E END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.DR_BALP_S) * -1 ELSE A.DR_BALP_E END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN A.DR_QTY_S*-1  ELSE A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {0} THEN (A.DR_BALP_S) * -1 ELSE A.DR_BALP_E END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_BALP_E - A.DR_BALP_E ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_E - A.DR_QTY_E ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_BALP_E - A.DR_BALP_E ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_AMT_Y ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_QTY_Y ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.CR_AMT_Y ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_AMT_Y ELSE 0 END) /  SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_QTY_Y ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD  WHEN {1} THEN A.DR_AMT_Y ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (isForCur == 1) {
                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "");
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, qtyTable, beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)  SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)  SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\t\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        param.put("qtyFindSql", qtyFindSql);
                    }

                    if (moneyType == -3) {
                        compidCondition = " AND A.STA_CUR =1 ";
                        allSelectMoney = ",-3 FOR_CUR";
                        allMoney = "";
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "");
                        findSql = findSql + " UNION ALL " + moneyCol;
                        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                            moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_MONTH_FOR_CUR, qtyTable, beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, MessageFormat.format(", A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END) QCYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S - A.DR_BALP_S END ELSE 0 END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)  SUM_J_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E END END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)  SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END) /  SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_E END END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {0} THEN (CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_S END)*-1  ELSE\n\t\t\t\t\t\t\tCASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_BALP_E END END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END ELSE 0 END)\n\t\t\tEND QMYE_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_JL_DJ,\t\n\t\t\t\n\t\t\tSUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END) <> 0 \n\t\t\t   THEN SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END) /  SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END ELSE 0 END)\n\t\t\t   ELSE SUM(CASE A.ACC_PERIOD WHEN {1} THEN CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END ELSE 0 END)\n\t\t\tEND SUM_DL_DJ,\t\n\t\t\t\n\t\t\t9999 BZLX", beginAccountId, endAccountId), " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                            qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                            param.put("qtyFindSql", qtyFindSql);
                        }
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                slzSelectCondition = "\t       ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y)) QCYE_SL, \n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y)) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y))  /  SUM(A.CR_QTY_E - A.DR_QTY_E  - (A.CR_QTY_Y - A.DR_QTY_Y))\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) \n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                    slzSelectCondition = "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(A.CR_QTY_S - A.DR_QTY_S) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_S - A.DR_QTY_S) <> 0 THEN SUM(A.CR_BALP_S - A.DR_BALP_S) /  SUM(A.CR_QTY_S - A.DR_QTY_S)\n\t\t\t   ELSE SUM(A.CR_BALP_S - A.DR_BALP_S)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.DR_QTY_TOT) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_TOT) <> 0 THEN SUM(A.DR_AMT_TOT) /  SUM(A.DR_QTY_TOT)\n\t\t\t   ELSE SUM(A.DR_AMT_TOT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_TOT) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_TOT) <> 0 THEN SUM(A.CR_AMT_TOT) /  SUM(A.CR_QTY_TOT)\n\t\t\t   ELSE SUM(A.CR_AMT_TOT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (isForCur == 1) {
                    slzSelectCondition = ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t        \n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL,\n\t\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)  <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) \n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\n\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) \n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        slzSelectCondition = ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "", "");
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        param.put("qtyFindSql", qtyFindSql);
                    }

                    if (moneyType == -3) {
                        compidCondition = " AND A.STA_CUR =1 ";
                        allSelectMoney = ",-3 FOR_CUR";
                        allMoney = "";
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "", "");
                        findSql = findSql + " UNION ALL " + allSql;
                        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                            String qtyAllSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, slzSelectCondition, " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                            qtyFindSql = qtyFindSql + " UNION ALL " + qtyAllSql;
                            param.put("qtyFindSql", qtyFindSql);
                        }
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_MONTH, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_MONTH, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(A.CR_QTY_S - A.DR_QTY_S) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_S - A.DR_QTY_S) <> 0 THEN SUM(A.CR_BALP_S - A.DR_BALP_S) /  SUM(A.CR_QTY_S - A.DR_QTY_S)\n\t\t\t   ELSE SUM(A.CR_BALP_S - A.DR_BALP_S)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.DR_QTY_TOT) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_TOT) <> 0 THEN SUM(A.DR_AMT_TOT) /  SUM(A.DR_QTY_TOT)\n\t\t\t   ELSE SUM(A.DR_AMT_TOT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_TOT) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_TOT) <> 0 THEN SUM(A.CR_AMT_TOT) /  SUM(A.CR_QTY_TOT)\n\t\t\t   ELSE SUM(A.CR_AMT_TOT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /  SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_MONTH_FOR_CUR, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    compidCondition = " AND A.STA_CUR =1 ";
                    allSelectMoney = ",-3 FOR_CUR";
                    allMoney = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, "", "");
                    findSql = findSql + " UNION ALL " + moneyCol;
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_MONTH_FOR_CUR, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, accoStatusContion, allMoney, allSelectMoney, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_S - A.DR_QTY_S END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) SUM_D_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_TOT END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0  \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0\n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)  /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_QUARTER, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, wdCol, accoStatusContion, "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_QUARTER, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, wdCol, accoStatusContion, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\n\t\t\t SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY) <> 0 \n\t\t\t   THEN SUM(A.CR_BALP_E - A.SE_DE_AMOUNT- A.DR_BALP_E + A.SE_CR_AMOUNT) /   SUM(A.CR_QTY_E - A.SE_DE_QTY- A.DR_QTY_E + A.SE_CR_QTY)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.SE_DE_AMOUNT- A.DR_BALP_E + A.SE_CR_AMOUNT)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(A.SE_DE_QTY) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.SE_DE_QTY) <> 0 THEN SUM(A.SE_DE_AMOUNT) /  SUM(A.SE_DE_QTY)\n\t\t\t   ELSE SUM(A.SE_DE_AMOUNT)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.SE_CR_QTY) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.SE_CR_QTY) <> 0 THEN SUM(A.SE_CR_AMOUNT) /  SUM(A.SE_CR_QTY)\n\t\t\t   ELSE SUM(A.SE_CR_AMOUNT)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /   SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX\t", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, wdCol, accoStatusContion, allMoney, allSelectMoney, "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, wdCol, accoStatusContion, allMoney, allSelectMoney, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE, \n\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END) /   SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    compidCondition = " AND A.STA_CUR =1 ";
                    allSelectMoney = ",-3 FOR_CUR";
                    allMoney = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, wdCol, accoStatusContion, allMoney, allSelectMoney, "", "");
                    findSql = findSql + " UNION ALL " + moneyCol;
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_BY_QUARTER_FOR_CUR, qtyTable, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, kmAndAccJoin, wdCol, accoStatusContion, allMoney, allSelectMoney, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE, \n\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) QCYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.SE_DE_QTY  - A.DR_QTY_E  + A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  - A.SE_DE_AMOUNT - A.DR_BALP_E  +  A.SE_CR_AMOUNT END)\n\t\t\tEND QCYE_DJ,\n\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) SUM_J_SL, \n\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_DE_AMOUNT END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_QTY END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.SE_CR_AMOUNT END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END) /   SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E  -  A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + moneyCol;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, "", "");
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, "\t\t\t,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y) <> 0 \n\t\t\t   THEN SUM( A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y) /   SUM(A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y )\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(A.CR_QTY_E - A.DR_QTY_E) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(A.CR_QTY_E - A.DR_QTY_E) <> 0 THEN SUM(A.CR_BALP_E - A.DR_BALP_E) /   SUM(A.CR_QTY_E - A.DR_QTY_E)\n\t\t\t   ELSE SUM(A.CR_BALP_E - A.DR_BALP_E)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\tSUM(A.CR_QTY_Y) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.CR_QTY_Y) <> 0 THEN SUM(A.CR_AMT_Y) /  SUM(A.CR_QTY_Y)\n\t\t\t   ELSE SUM(A.CR_AMT_Y)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(A.DR_QTY_Y) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(A.DR_QTY_Y) <> 0 THEN SUM(A.DR_AMT_Y) /  SUM(A.DR_QTY_Y)\n\t\t\t   ELSE SUM(A.DR_AMT_Y)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                param.put("qtyFindSql", qtyFindSql);
            }

            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "", "");
                if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                    qtyFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                    param.put("qtyFindSql", qtyFindSql);
                }

                if (moneyType == -3) {
                    compidCondition = " AND A.STA_CUR =1 ";
                    allSelectMoney = ",-3 FOR_CUR";
                    allMoney = "";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, "", "");
                    findSql = findSql + " UNION ALL " + moneyCol;
                    if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                        slzSelectCondition = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HZ_INFO_FOR_ONE_MONTH_FOR_CUR, qtyTable, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, wdCol, kmAndAccJoin, moneyCol, accoStatusContion, allMoney, allSelectMoney, ",A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE,\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) QCYE_SL, \n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E - A.CR_QTY_Y + A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END)\n\t\t\tEND QCYE_DJ,\n\t\t\t\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) SUM_J_SL, \n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_J_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) SUM_D_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_D_DJ,\n\t\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) QMYE_SL,\n\t\t\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_E - A.DR_QTY_E END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_BALP_E - A.DR_BALP_E END)\n\t\t\tEND QMYE_DJ,\n\t\t\n\t\t\t SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) SUM_JL_SL,\n\n\t\t\tCASE \n\t\t\t   WHEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END) <> 0 \n\t\t\t   THEN  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END) /   SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_QTY_Y END)\n\t\t\t   ELSE  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.CR_AMT_Y END)\n\t\t\tEND SUM_JL_DJ,\n\t\t\t\n\t\t\tSUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) SUM_DL_SL,\n\t\t\t\n\t\t\tCASE \n\t\t\t   WHEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END) <> 0 \n\t\t\t   THEN SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END) /  SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_QTY_Y END)\n\t\t\t   ELSE SUM(CASE A.STA_CUR  WHEN -1 THEN  0  ELSE A.DR_AMT_Y END)\n\t\t\tEND SUM_DL_DJ,\n\t\t\t9999 BZLX", " ,A.MEASUR_UNIT,A.MEAS_UNIT_GROUP_CODE");
                        qtyFindSql = qtyFindSql + " UNION ALL " + slzSelectCondition;
                        param.put("qtyFindSql", qtyFindSql);
                    }
                }
            }
        }

        findSql = AccComprehensiveQueryConvertSqlDao.unionConcatSql(findSql, param);
        return findSql;
    }

    private String buildHbSqlForDim(Map<String, Object> param) {
        String findSql = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("moneyTypeCondition"));
        String osetCompidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
        String osetMoneyTypeOption = ConvertUtil.toString(param.get("osetMoneyTypeOption"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        String wdCondition = ConvertUtil.toString(param.get("wdCondition"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = ",A.STA_CUR";
        if (moneyType == -3) {
            allSelectMoney = ",FOR_CUR";
            allMoney = ",FOR_CUR";
        }

        String wdCon = "";
        if (StringUtils.isNotEmpty(wdCondition)) {
            wdCon = " AND (" + wdCondition + ")";
        }

        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        StringBuilder fromTable = new StringBuilder("");
        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        String balTable = "ACC_BAL_DIM_SUM{1}";
        String vTableName = "";
        if (!isBottomUnit) {
            balTable = "ACC_BAL_DIM_SUM{1}_TOP";
        }

        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_SUM{1}";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
            if (!isBottomUnit) {
                balTable = "{0}ACC_PFT_BAL_SUM{1}_TOP";
            }
        }

        vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            fromTable.append("(SELECT " + fileds + " FROM " + vTableName + " T )");
        } else {
            fromTable.append(vTableName);
        }

        fromTable.append(" A ");
        StringBuilder fromOsetTable = new StringBuilder("");
        fromOsetTable.append(MessageFormat.format("OSET_BAL_DIM_SUM{1}_TOP", "", accountYear));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        boolean isMxDwQuery = mxdwQuery != null && mxdwQuery == 1;
        if (isMxDwQuery) {
            fromOsetTable = new StringBuilder();
            fromOsetTable.append(MessageFormat.format("OSET_BAL_DIM_SUM{1}", "", accountYear));
        }

        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        fromOsetTable.append(" A ");
        String bzlx = "";
        String hzBzlx = "";
        String dxBzlx = "";
        if ("MERGEDATA".equals(dataOption) && isMxDwQuery) {
            bzlx = " ,bzlx ";
            hzBzlx = " , 0 bzlx ";
            dxBzlx = " , 1 bzlx ";
        }

        String moneyCol;
        String osetMoneyCol;
        String bwbMoney;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, accoStatusContion, hzBzlx, dxBzlx, bzlx);
                if (isForCur == 1) {
                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        moneyCol = ", -3 FOR_CUR";
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, ", -3 FOR_CUR", allSelectMoney);
                        findSql = findSql + " UNION ALL " + moneyCol;
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, moneyCol, accoStatusContion, hzBzlx, dxBzlx, bzlx);
                if (isForCur == 1) {
                    osetMoneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        osetMoneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                        moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        osetMoneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                            osetMoneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    if (moneyType == -3) {
                        osetMoneyTypeOption = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, moneyCol, osetMoneyCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        bwbMoney = ", -3 FOR_CUR";
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, moneyCol, osetMoneyCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, ", -3 FOR_CUR", allSelectMoney);
                        findSql = findSql + " UNION ALL " + allSql;
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_BY_MONTH, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, accoStatusContion, hzBzlx, dxBzlx, bzlx);
            if (isForCur == 1) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    moneyCol = ", -3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, ", -3 FOR_CUR", allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_BY_QUARTER, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, accoStatusContion, hzBzlx, dxBzlx, bzlx);
            if (isForCur == 1) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    moneyCol = ", -3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, ", -3 FOR_CUR", allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, moneyCol, accoStatusContion, hzBzlx, dxBzlx, bzlx);
            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, moneyCol, moneyCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    osetMoneyCol = ", -3 FOR_CUR";
                    bwbMoney = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, wdCol, moneyCol, moneyCol, accoStatusContion, hzBzlx, dxBzlx, bzlx, ", -3 FOR_CUR", allSelectMoney);
                    findSql = findSql + " UNION ALL " + bwbMoney;
                }
            }
        }

        if (isMxDwQuery && findSql.contains("A.DATA_TYPE = 1")) {
            findSql = findSql.replace("A.DATA_TYPE = 1", "A.DATA_TYPE = 0");
        }

        return findSql;
    }

    private String buildHbSqlForOneDim(Map<String, Object> param) {
        String findSql = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("compidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("moneyTypeCondition"));
        String osetCompidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
        String osetMoneyTypeOption = ConvertUtil.toString(param.get("osetMoneyTypeOption"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        boolean isBottomUnit = ConvertUtil.toBoolean(param.get("isBottomUnit"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        String accoStatusContion = ConvertUtil.toString(param.get("accoStatusContion"));
        int limitCount = ConvertUtil.toInt(param.get("hzDataLimit"));
        String accoStatus = ConvertUtil.toString(param.get("accoStatus"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = "";
        if (moneyType == -3) {
            allSelectMoney = ",FOR_CUR";
            allMoney = ",FOR_CUR";
        }

        String wdCondition = ConvertUtil.toString(param.get("wdCondition"));
        StringBuilder groupByDimGroup = new StringBuilder("");
        StringBuilder groupByDimGroupOset = new StringBuilder("");
        int isGroupByDimGroup = ConvertUtil.toInt(param.get("isGroupByDimGroup"));
        Integer oneDimIsCls = ConvertUtil.toInteger(param.get("oneDimIsCls"));
        if (isGroupByDimGroup == 1) {
            groupByDimGroup.append(", A.ACC_PERIOD,A.DIM_GROUP");
            groupByDimGroupOset.append(",A.DIM_GROUP");
            if (isForCur == 1) {
                groupByDimGroup.append(",A.STA_CUR");
                groupByDimGroupOset.append(",A.STA_CUR");
            }

            if ("0".equals(accoStatus)) {
                groupByDimGroup.append(",A.ENTRY_MARK");
            }
        } else if (oneDimIsCls == 1) {
            groupByDimGroup.append(",A.DIM_VAL");
            groupByDimGroupOset.append(",A.DTL_DIM_ID");
        } else if (DBUtil.isMySql()) {
            groupByDimGroup.append(",A.DIM_VAL ");
            groupByDimGroupOset.append(",A.DTL_DIM_ID");
        } else if (limitCount > 0) {
            groupByDimGroup.append(",A.DIM_VAL ");
            groupByDimGroupOset.append(",A.DTL_DIM_ID");
        } else {
            groupByDimGroup.append(",NVL(F.OBJ_ID1, A.DIM_VAL)");
            groupByDimGroupOset.append(",NVL(F.OBJ_ID1, A.DTL_DIM_ID)");
        }

        String wdCon = "";
        if (StringUtils.isNotEmpty(wdCondition)) {
            wdCon = " AND (" + wdCondition + ")";
        }

        String wdConOset = StringUtils.replace(wdCon, "A.DIM_VAL", "A.DTL_DIM_ID");
        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        StringBuilder fromTable = new StringBuilder("");
        String colToRowWdCol = ConvertUtil.toString(param.get("colToRowWdCol"));
        String colToRowWdColOset = StringUtils.replace(colToRowWdCol, "A.DIM_VAL", "A.DTL_DIM_ID");
        String selectPftCompId = ConvertUtil.toString(param.get("selectPftCompId"));
        String balTable = "ACC_BAL_DIM_ROW{1}";
        String vTableName = "";
        if (!isBottomUnit) {
            balTable = "ACC_BAL_DIM_ROW{1}_TOP";
        }

        String fileds = null;
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            balTable = "{0}ACC_PFT_BAL_DIM_ROW{1}";
            fileds = " T.PROF_CEN FINA_ORG, T.* ";
            if (!isBottomUnit) {
                balTable = "{0}ACC_PFT_BAL_DIM_ROW{1}_TOP";
            }
        }

        vTableName = MessageFormat.format(balTable, "", accountYear);
        if (StringUtils.isNotEmpty(selectPftCompId)) {
            fromTable.append("(SELECT " + fileds + " FROM " + vTableName + " T)");
        } else {
            fromTable.append(vTableName);
        }

        fromTable.append(" A ");
        StringBuilder fromOsetTable = new StringBuilder("");
        fromOsetTable.append(MessageFormat.format("OSET_BAL_DIM_ROW{1}_TOP", "", accountYear));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        if (mxdwQuery != null && mxdwQuery == 1) {
            fromOsetTable = new StringBuilder("");
            fromOsetTable.append(MessageFormat.format("OSET_BAL_DIM_ROW{1}", "", accountYear));
        }

        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String bzlx = "";
        String hzBzlx = "";
        String dxBzlx = "";
        if ("MERGEDATA".equals(dataOption) && mxdwQuery != null && mxdwQuery == 1) {
            bzlx = " ,bzlx ";
            hzBzlx = " , 0 bzlx ";
            dxBzlx = " , 1 bzlx ";
        }

        fromOsetTable.append(" A ");
        String moneyCol;
        String osetMoneyCol;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, accoStatusContion, bzlx, hzBzlx, dxBzlx, groupByDimGroupOset.toString(), colToRowWdColOset, wdConOset);
                if (isForCur == 1) {
                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        colToRowWdCol = colToRowWdCol.replaceAll(",FOR_CUR", ",-3 FOR_CUR");
                        osetMoneyTypeOption = "AND A.STA_CUR =1";
                        allSelectMoney = ",-3 FOR_CUR";
                        allMoney = "";
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                        findSql = findSql + " UNION ALL " + moneyCol;
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, moneyCol, accoStatusContion, bzlx, hzBzlx, dxBzlx, groupByDimGroupOset.toString(), colToRowWdColOset, wdConOset);
                if (isForCur == 1) {
                    osetMoneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        osetMoneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                        moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        osetMoneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                            osetMoneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    if (moneyType == -3) {
                        osetMoneyTypeOption = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, moneyCol, osetMoneyCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        osetMoneyTypeOption = " AND A.STA_CUR =1 ";
                        allSelectMoney = ",-3 FOR_CUR";
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, moneyCol, osetMoneyCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                        findSql = findSql + " UNION ALL " + allSql;
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_BY_MONTH, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, accoStatusContion, bzlx, hzBzlx, dxBzlx, groupByDimGroup.toString(), colToRowWdColOset, wdConOset);
            if (isForCur == 1) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    colToRowWdCol = colToRowWdCol.replaceAll(",FOR_CUR", ",-3 FOR_CUR");
                    osetMoneyTypeOption = "AND A.STA_CUR =1";
                    allSelectMoney = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_BY_QUARTER, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, accoStatusContion, bzlx, hzBzlx, dxBzlx, colToRowWdColOset, wdConOset);
            if (isForCur == 1) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    colToRowWdCol = colToRowWdCol.replaceAll(",FOR_CUR", ",-3 FOR_CUR");
                    osetMoneyTypeOption = "AND A.STA_CUR =1";
                    allSelectMoney = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, moneyCol, accoStatusContion, bzlx, hzBzlx, dxBzlx, colToRowWdColOset, wdConOset);
            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, moneyCol, moneyCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    colToRowWdCol = colToRowWdCol.replaceAll(",FOR_CUR", ",-3 FOR_CUR");
                    osetMoneyTypeOption = "AND A.STA_CUR =1";
                    allSelectMoney = ",-3 FOR_CUR";
                    osetMoneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_HB_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, accbookid, fromOsetTable.toString(), osetCompidCondition, osetMoneyTypeOption, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), wdCol, moneyCol, moneyCol, accoStatusContion, groupByDimGroupOset.toString(), bzlx, hzBzlx, dxBzlx, allMoney, allSelectMoney, colToRowWdColOset, wdConOset);
                    findSql = findSql + " UNION ALL " + osetMoneyCol;
                }
            }
        }

        if (isGroupByDimGroup == 1) {
            if (DBUtil.isMySql()) {
                findSql = findSql.replaceAll("SUM\\(A\\.", "MAX(A.").replaceAll("SUM\\(CASE", "MAX(CASE");
            } else {
                findSql = findSql.replaceAll("SUM\\(A\\.", "MAX(A.").replaceAll("SUM\\(DECODE\\(A\\.", "MAX(DECODE(A.");
            }
        }

        if (mxdwQuery != null && mxdwQuery == 1 && findSql.contains("A.DATA_TYPE = 1")) {
            findSql = findSql.replace("A.DATA_TYPE = 1", "A.DATA_TYPE = 0");
        }

        return findSql;
    }

    private String buildOsetSqlForDim(Map<String, Object> param) {
        String findSql = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("osetMoneyTypeOption"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        String wdCondition = ConvertUtil.toString(param.get("wdCondition"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = ", FOR_CUR";
        if (moneyType == -3) {
            allSelectMoney = ", FOR_CUR";
            allMoney = ",FOR_CUR";
        }

        String wdCon = "";
        if (StringUtils.isNotEmpty(wdCondition)) {
            wdCon = " AND (" + wdCondition + ")";
        }

        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        String osetTypeCom = "";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String balTable;
        if ("CONTRADATA1".equals(dataOption)) {
            osetTypeCom = " AND A.DATA_TYPE = 1 ";
            balTable = "OSET_BAL_DIM_SUM{1}_TOP";
        } else {
            osetTypeCom = " AND A.DATA_TYPE = 0 ";
            balTable = "OSET_BAL_DIM_SUM{1}";
        }

        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        if (dataOption.contains("CONTRADATA") && mxdwQuery != null && mxdwQuery == 1) {
            osetTypeCom = " AND A.DATA_TYPE = 0 ";
            balTable = "OSET_BAL_DIM_SUM{1}";
        }

        StringBuilder fromTable = new StringBuilder("");
        String wdCol = ConvertUtil.toString(param.get("wdCol"));
        String vTableName = "";
        vTableName = MessageFormat.format(balTable, "", accountYear);
        fromTable.append(vTableName);
        fromTable.append(" A ");
        String moneyCol;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol);
                if (isForCur == 1) {
                    if (moneyType == -3) {
                        moneyTypeCondition = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allSelectMoney = ",-3 FOR_CUR";
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, allMoney, allSelectMoney);
                        findSql = findSql + " UNION ALL " + moneyCol;
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, moneyCol);
                if (isForCur == 1) {
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, moneyCol, allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        allSelectMoney = ",-3 FOR_CUR";
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, moneyCol, allMoney, allSelectMoney);
                        findSql = findSql + " UNION ALL " + allSql;
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_BY_MONTH, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol);
            if (isForCur == 1) {
                if (moneyType == -3) {
                    moneyTypeCondition = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allSelectMoney = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, allMoney, allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_BY_QUARTER, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol);
            if (isForCur == 1) {
                if (moneyType == -3) {
                    moneyTypeCondition = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allSelectMoney = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, allMoney, allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, moneyCol);
            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                }

                if (moneyType == -3) {
                    moneyTypeCondition = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, moneyCol, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    allSelectMoney = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, wdCol, moneyCol, allMoney, allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        }

        return findSql;
    }

    private String buildOsetSqlForOneDim(Map<String, Object> param) {
        String findSql = "";
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        String compidCondition = ConvertUtil.toString(param.get("osetCompidCondition"));
        String moneyTypeCondition = ConvertUtil.toString(param.get("osetMoneyTypeOption"));
        String accbookid = ConvertUtil.toString(param.get("accbookid"));
        String subjectCondition = ConvertUtil.toString(param.get("subjectCondition"));
        String beginAccountId = ConvertUtil.toString(param.get("beginAccount"));
        String endAccountId = ConvertUtil.toString(param.get("endAccount"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String dateStatus = ConvertUtil.toString(param.get("dateStatus"));
        int limitCount = ConvertUtil.toInt(param.get("hzDataLimit"));
        String wdCondition = ConvertUtil.toString(param.get("wdCondition"));
        StringBuilder groupByDimGroup = new StringBuilder("");
        int isGroupByDimGroup = ConvertUtil.toInt(param.get("isGroupByDimGroup"));
        Integer oneDimIsCls = ConvertUtil.toInteger(param.get("oneDimIsCls"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String allMoney = "";
        String allSelectMoney = "";
        if (moneyType == -3) {
            allSelectMoney = ",FOR_CUR";
            allMoney = ",FOR_CUR";
        }

        if (isGroupByDimGroup == 1) {
            groupByDimGroup.append(", A.ACC_PERIOD,A.DIM_GROUP");
            if (isForCur == 1) {
                groupByDimGroup.append(",A.STA_CUR");
            }
        } else if (oneDimIsCls == 1) {
            groupByDimGroup.append(",A.DTL_DIM_ID");
        } else if (DBUtil.isMySql()) {
            groupByDimGroup.append(",A.DTL_DIM_ID");
        } else if (limitCount > 0) {
            groupByDimGroup.append(",A.DTL_DIM_ID");
        } else {
            groupByDimGroup.append(",NVL(F.OBJ_ID1, A.DTL_DIM_ID)");
        }

        String wdCon = "";
        if (StringUtils.isNotEmpty(wdCondition)) {
            wdCon = " AND (" + wdCondition + ")";
            wdCon = StringUtils.replace(wdCon, "A.DIM_VAL", "A.DTL_DIM_ID");
        }

        String kmAndAccJoin = "";
        if (param.get("kmAndAccJoinTable") != null) {
            kmAndAccJoin = ConvertUtil.toString(param.get("kmAndAccJoinTable"));
        }

        String osetTypeCom = "";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String balTable = "OSET_BAL_DIM_ROW{1}_TOP";
        if ("CONTRADATA1".equals(dataOption)) {
            balTable = "OSET_BAL_DIM_ROW{1}_TOP";
            osetTypeCom = " AND A.DATA_TYPE = 1 ";
        } else {
            osetTypeCom = " AND A.DATA_TYPE = 0 ";
            balTable = "OSET_BAL_DIM_ROW{1}";
        }

        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        if (mxdwQuery != null && mxdwQuery == 1) {
            osetTypeCom = " AND A.DATA_TYPE = 0 ";
            balTable = "OSET_BAL_DIM_ROW{1}";
        }

        StringBuilder fromTable = new StringBuilder("");
        String colToRowWdCol = ConvertUtil.toString(param.get("colToRowWdCol"));
        colToRowWdCol = StringUtils.replace(colToRowWdCol, "A.DIM_VAL", "A.DTL_DIM_ID");
        String vTableName = "";
        vTableName = MessageFormat.format(balTable, "", accountYear);
        fromTable.append(vTableName);
        fromTable.append(" A ");
        String moneyCol;
        String bwbMoney;
        if ("0".equals(dateStatus)) {
            if (!"01".equals(beginAccountId.substring(4, 6)) && !endAccountId.equals(beginAccountId)) {
                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_FOR_MONTH, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString());
                if (isForCur == 1) {
                    if (moneyType == -3) {
                        moneyTypeCondition = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        moneyCol = ",-3 FOR_CUR";
                        moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_FOR_MONTH_FOR_CUR, fromTable.toString(), beginAccountId, endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), ",-3 FOR_CUR", allSelectMoney);
                        findSql = findSql + " UNION ALL " + moneyCol;
                    }
                }
            } else {
                int isSameAccount = ConvertUtil.toInt(param.get("isSameAccount"));
                moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
                if (isSameAccount == 1) {
                    moneyCol = "SUM(A.CR_BALP_S - A.DR_BALP_S) QCYE_BWB, SUM(A.DR_AMT_TOT) SUM_J_BWB, SUM(A.CR_AMT_TOT) SUM_D_BWB";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), moneyCol);
                if (isForCur == 1) {
                    moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                    if (DBUtil.isMySql()) {
                        moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                    }

                    if (isSameAccount == 1) {
                        moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_S - A.DR_BALP_S, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_S - A.DR_BALP_S)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_TOT, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_TOT)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_TOT, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_TOT)) SUM_D_BWB";
                        if (DBUtil.isMySql()) {
                            moneyCol = "SUM(CASE A.STA_CUR WHEN -1 THEN  A.CR_BALP_S - A.DR_BALP_S ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_S - A.DR_BALP_S END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_TOT  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_TOT END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_TOT  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_TOT END) SUM_D_BWB";
                        }
                    }

                    if (moneyType == -3) {
                        moneyTypeCondition = "";
                    }

                    findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), moneyCol, allMoney, allSelectMoney);
                    if (moneyType == -3) {
                        moneyTypeCondition = " AND A.STA_CUR =1 ";
                        bwbMoney = ",-3 FOR_CUR";
                        allSelectMoney = "";
                        String allSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), moneyCol, ",-3 FOR_CUR", allSelectMoney);
                        findSql = findSql + " UNION ALL " + allSql;
                    }
                }
            }
        } else if ("1".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_BY_MONTH, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString());
            if (isForCur == 1) {
                if (moneyType == -3) {
                    moneyTypeCondition = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    moneyCol = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_BY_MONTH_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), ",-3 FOR_CUR", allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("2".equals(dateStatus)) {
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_BY_QUARTER, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString());
            if (isForCur == 1) {
                if (moneyType == -3) {
                    moneyTypeCondition = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    moneyCol = ",-3 FOR_CUR";
                    moneyCol = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_BY_QUARTER_FOR_CUR, fromTable.toString(), wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), ",-3 FOR_CUR", allSelectMoney);
                    findSql = findSql + " UNION ALL " + moneyCol;
                }
            }
        } else if ("3".equals(dateStatus)) {
            moneyCol = "SUM(A.CR_BALP_E - A.DR_BALP_E  - (A.CR_AMT_Y - A.DR_AMT_Y)) QCYE_BWB, SUM(A.CR_AMT_Y) SUM_J_BWB, SUM(A.DR_AMT_Y) SUM_D_BWB";
            findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_FOR_ONE_MONTH, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), moneyCol);
            if (isForCur == 1) {
                moneyCol = "SUM(DECODE(A.STA_CUR, -1, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y, 0)) QCYE,SUM(DECODE(A.STA_CUR, -1, 0, A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y)) QCYE_BWB,SUM(DECODE(A.STA_CUR, -1, A.CR_AMT_Y, 0)) SUM_J, SUM(DECODE(A.STA_CUR, -1, 0, A.CR_AMT_Y)) SUM_J_BWB,SUM(DECODE(A.STA_CUR, -1, A.DR_AMT_Y, 0)) SUM_D, SUM(DECODE(A.STA_CUR, -1, 0, A.DR_AMT_Y)) SUM_D_BWB";
                if (DBUtil.isMySql()) {
                    moneyCol = "SUM(CASE A.STA_CUR  WHEN -1 THEN  A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y  ELSE 0 END) QCYE,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_BALP_E - A.DR_BALP_E - A.CR_AMT_Y + A.DR_AMT_Y END) QCYE_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.CR_AMT_Y  ELSE 0 END) SUM_J,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.CR_AMT_Y END) SUM_J_BWB,SUM(CASE A.STA_CUR WHEN -1 THEN A.DR_AMT_Y  ELSE 0 END) SUM_D,SUM(CASE A.STA_CUR WHEN -1 THEN 0 ELSE A.DR_AMT_Y END) SUM_D_BWB";
                }

                if (moneyType == -3) {
                    moneyTypeCondition = "";
                }

                findSql = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), moneyCol, allMoney, allSelectMoney);
                if (moneyType == -3) {
                    moneyTypeCondition = " AND A.STA_CUR =1 ";
                    moneyCol = ",-3 FOR_CUR";
                    bwbMoney = MessageFormat.format(AccComprehensiveQueryDaoConst.FIND_ONE_DIM_OSET_INFO_FOR_ONE_MONTH_FOR_CUR, fromTable.toString(), endAccountId, wdCon, subjectCondition, compidCondition, moneyTypeCondition, osetTypeCom, accbookid, kmAndAccJoin, colToRowWdCol, groupByDimGroup.toString(), moneyCol, ",-3 FOR_CUR", allSelectMoney);
                    findSql = findSql + " UNION ALL " + bwbMoney;
                }
            }
        }

        if (isGroupByDimGroup == 1) {
            if (DBUtil.isMySql()) {
                findSql = findSql.replaceAll("SUM\\(A\\.", "MAX(A.").replaceAll("SUM\\(CASE", "MAX(CASE");
            } else {
                findSql = findSql.replaceAll("SUM\\(A\\.", "MAX(A.").replaceAll("SUM\\(DECODE\\(A\\.", "MAX(DECODE(A.");
            }
        }

        return findSql;
    }

    private String buildFindSqlFromSoureTable(Map<String, Object> param) {
        int isFromAccBalSum = ConvertUtil.toInt(param.get("isFromAccBalSum"));
        boolean isShowAllWd = ConvertUtil.toBoolean(param.get("isShowAllWd"));
        return (String) AccConditionUtils.isAllMatch(new Boolean[]{isFromAccBalSum == 1 && !isShowAllWd}).handleConditionWithReturn(() -> {
            return this.buildSqlForKm(param);
        }, () -> {
            Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
            return (String)AccConditionUtils.isAllMatch(new Boolean[]{isOneDimQuery == null || isOneDimQuery == 0}).handleConditionWithReturn(() -> {
                Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
                return (String)AccConditionUtils.isAllMatch(new Boolean[]{dimClsIsSelectOneCol != null && dimClsIsSelectOneCol == 1 || isShowAllWd}).handleConditionWithReturn(() -> {
                    return (String)AccConditionUtils.isAllMatch(new Boolean[]{isShowAllWd}).handleConditionWithReturn(() -> {
                        return this.buildSqlForKmShowAllDim(param);
                    }, () -> {
                        return this.buildSqlForOneDim(param);
                    });
                }, () -> {
                    return this.buildSqlForDim(param);
                });
            }, () -> {
                return this.buildSqlForOneDim(param);
            });
        });
    }

    private String getQuerySqlByKm(String findTwoSql, Map<String, Object> param) {
        String kmlevel = ConvertUtil.toString(param.get("kmLevel"));
        String isShowStopedKm = ConvertUtil.toString(param.get("isShowStopedKm"));
        boolean isShowHzByStep = ConvertUtil.toBoolean(param.get("isShowHzByStep"));
        Integer fzmxQuery = ConvertUtil.toInteger(param.get("fzmxQuery"));
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer isSelectDimValue = ConvertUtil.toInteger(param.get("isSelectDimValue"));
        int isFromAccBalSum = ConvertUtil.toInt(param.get("isFromAccBalSum"));
        boolean isShowAllWd = ConvertUtil.toBoolean(param.get("isShowAllWd"));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        String queryModel = ConvertUtil.toString(param.get("queryModel"));
        Integer dimClsIsSelectOneCol = ConvertUtil.toInteger(param.get("dimClsIsSelectOneCol"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String dataTypeSumCondition = ConvertUtil.toString(param.get("dataTypeSumCondition"));
        Integer isShowAllWdHaveOrOneDim = ConvertUtil.toInteger(param.get("isShowAllWdHaveOrOneDim"));
        boolean levelDetails = ConvertUtil.toBoolean(param.get("levelDetails"));
        boolean isShowByUnitTotal = ConvertUtil.toBoolean(param.get("isShowByUnitTotal"));
        String xjmxCondition = " ";
        String xjmxHavinCondition = " ";
        if (ConvertUtil.toBoolean(param.get("xjmx")) || isShowAllWd) {
            xjmxCondition = " ,BZRED ";
            if (StringUtils.isNotEmpty(dataTypeSumCondition)) {
                xjmxHavinCondition = " AND ((A.LEAF = 0 AND BZRED = 0) OR (A.LEAF <> 0)) ";
            } else {
                xjmxHavinCondition = " HAVING ((A.LEAF = 0 AND BZRED = 0) OR (A.LEAF <> 0)) ";
            }
        }

        String selectQtWdCol = "";
        if (param.get("wdCol") != null) {
            selectQtWdCol = ConvertUtil.toString(param.get("wdCol"));
        }

        String qtRowCol = "";
        if (param.get("qtRowCol") != null) {
            qtRowCol = ConvertUtil.toString(param.get("qtRowCol"));
            if (mxdwQuery != null && mxdwQuery == 1 && isSelectDimValue != null && isSelectDimValue == 0) {
                qtRowCol = "";
            }
        }

        boolean isShowDesKmDx = ConvertUtil.toBoolean(param.get("isShowDesKmDx"));
        String qtGroupRowCol = "";
        if (param.get("qtGroupRowCol") != null) {
            qtGroupRowCol = ConvertUtil.toString(param.get("qtGroupRowCol"));
            if (mxdwQuery != null && mxdwQuery == 1 && isSelectDimValue != null && isSelectDimValue == 0) {
                qtGroupRowCol = "";
            }
        }

        String qtOrderRowCol = "";
        if (param.get("qtOrderRowCol") != null) {
            qtOrderRowCol = ConvertUtil.toString(param.get("qtOrderRowCol"));
            if (mxdwQuery != null && mxdwQuery == 1 && isSelectDimValue != null && isSelectDimValue == 0) {
                qtOrderRowCol = "";
            }
        }

        String rollupRowCon = "";
        if (param.get("rollupRowCon") != null) {
            rollupRowCon = ConvertUtil.toString(param.get("rollupRowCon"));
        }

        String rollupRowCondition = "";
        String rollupRow = "";
        String rollupHaving = "";
        String levelRollUpWdCol = selectQtWdCol;
        String selectMxField = "";
        String mxGroupByField = "";
        if (this.isNcYe(param)) {
            selectMxField = ",SUM(QMYE_HL) QCYE_NC, SUM(QCYE_HL) QCYE_BWB_NC";
            mxGroupByField = "";
        }

        String companyinfo;
        if (StringUtils.isNotEmpty(selectQtWdCol)) {
            if ((mxdwQuery == null || mxdwQuery != 1) && (fzmxQuery == null || fzmxQuery != 1) && !"1".equals(queryModel) && !isShowAllWd && dimClsIsSelectOneCol != 1) {
                rollupRow = ",ROLLUP(" + selectQtWdCol.substring(1, selectQtWdCol.length()) + ")";
                if (selectQtWdCol.split(",").length > 2) {
                    rollupRowCondition = " AND (" + rollupRowCon + ")";
                }

                qtGroupRowCol = selectQtWdCol;
                if (levelDetails) {
                    companyinfo = selectQtWdCol.split(",")[1];
                    if (DBUtil.isMySql()) {
                        levelRollUpWdCol = selectQtWdCol + " WITH ROLLUP  HAVING  " + companyinfo + " IS NOT NULL ";
                    } else {
                        levelRollUpWdCol = ",ROLLUP(" + selectQtWdCol.substring(1) + ") HAVING  " + companyinfo + " IS NOT NULL ";
                    }
                }

                rollupHaving = "HAVING A.LEAF=1 OR " + selectQtWdCol.split(",")[1] + " IS NULL ";
            }
        }

        companyinfo = ConvertUtil.toString(param.get("companyinfo"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String querySql = "";
        String kmLevelFilter = "";
        String kmShowStopFilter = "";
        if (!"1".equals(isShowStopedKm)) {
            if (DBUtil.isMySql()) {
                kmShowStopFilter = " AND A.STOPED = 0 ";
            } else {
                kmShowStopFilter = " AND A.STOPED = 0 ";
            }
        }

        if ((fzmxQuery == null || fzmxQuery != 1) && (mxdwQuery == null || mxdwQuery != 1) && !isShowAllWd) {
            if (!"0".equals(kmlevel)) {
                kmLevelFilter = " WHERE A.ITEMLEVEL <= " + param.get("kmLevel");
            } else {
                kmLevelFilter = " WHERE A.LEAF = 1 ";
            }
        } else {
            kmLevelFilter = " WHERE A.LEAF = 1 ";
            if (mxdwQuery != null && mxdwQuery == 1 & isShowDesKmDx) {
                qtGroupRowCol = selectQtWdCol;
            }

            rollupHaving = dataTypeSumCondition;
        }

        String compCol = ",C.PCOMPID, C.COMPNAME DWMC,C.LEAF COMPLEAF";
        String compJoin = ", (" + companyinfo + ") C";
        if (mxdwQuery != null && mxdwQuery == 1) {
            compJoin = ", " + companyinfo + " C";
        }

        String compCon = "  AND B.COMPID = C.COMPID ";
        String compGroup = ", C.PCOMPID,C.COMPNAME,C.LEAF";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String bzlx = "";
        if ("MERGEDATA".equals(dataOption) && mxdwQuery != null && mxdwQuery == 1) {
            bzlx = " ,BZLX ";
            compGroup = ", C.PCOMPID,C.COMPNAME,C.LEAF, B.BZLX ";
            compCol = ", C.PCOMPID,CASE COALESCE(B.bzlx,0) WHEN 1 THEN CONCAT(COALESCE(C.COMPNAME, ''),'抵销账') ELSE C.COMPNAME END DWMC,C.LEAF COMPLEAF";
        }

        String bzxz;
        if (mxdwQuery == null || mxdwQuery == 0) {
            Integer isExport = ConvertUtil.toInteger(param.get("isExport"));
            if (isExport == 0) {
                bzxz = ConvertUtil.toString(param.get("compname"));
                compCol = ",'0' PCOMPID, '" + bzxz + "' AS DWMC,1 AS COMPLEAF";
                compJoin = "";
                compCon = "";
                compGroup = "";
            }
        }

        boolean isShowEmptyDimensionValue = ConvertUtil.toBoolean(param.get("isShowEmptyDimensionValue"));
        bzxz = "";
        String bzxzB = "";
        if (isShowEmptyDimensionValue) {
            bzxz = " ,BZXZ ";
            bzxzB = " ,B.BZXZ ";
        }

        String unitTotal = ",COMPID";
        String commaBUnitTotal = ",B.COMPID";
        String bUnitTotalComma = "B.COMPID,";
        String pUnitTotal = ",PCOMPID,DWMC,COMPLEAF";
        if (isShowByUnitTotal && (mxdwQuery == null || mxdwQuery != 1)) {
            unitTotal = "";
            commaBUnitTotal = "";
            bUnitTotalComma = "";
            compGroup = "";
            compCol = "";
            pUnitTotal = "";
        }

        String mysqlDimCol = "";
        mysqlDimCol = selectQtWdCol.replaceAll(",", ", NULL AS ");
        rollupRowCondition = "";
        String kmRetrunFilter = kmLevelFilter + kmShowStopFilter;
        if (isShowHzByStep) {
            rollupRowCondition = "";
        }

        String select_key_value_sql_filed;
        if (isShowDesKmDx) {
            qtRowCol = selectQtWdCol;
            qtOrderRowCol = selectQtWdCol.replaceAll(", WD", " DESC , WD").replaceFirst("DESC", "") + " ASC";
            if (!DBUtil.isMySql()) {
                StringBuilder sb = new StringBuilder(",");
                if (StringUtils.isNotEmpty(qtOrderRowCol) && qtOrderRowCol.length() > 4) {
                    select_key_value_sql_filed = qtOrderRowCol.substring(1, qtOrderRowCol.length() - 4);
                    if (StringUtils.isNotEmpty(select_key_value_sql_filed) && select_key_value_sql_filed.contains(",")) {
                        Arrays.stream(select_key_value_sql_filed.split(",")).forEach((e) -> {
                            sb.append(e + " ASC NULLS FIRST ,");
                        });
                        qtOrderRowCol = sb.substring(0, sb.length() - 1);
                    } else {
                        qtOrderRowCol = qtOrderRowCol + " NULLS FIRST  ";
                    }
                } else {
                    qtOrderRowCol = qtOrderRowCol + " NULLS FIRST  ";
                }
            }

            rollupHaving = "";
        }

        String select_key_value_gt_zw_wd_bill_mx_sql_filed = "";
        select_key_value_sql_filed = "";
        String select_key_value_sql_filed2 = "";
        String group_by_add_num_type = "";
        if (StringUtils.equals(ConvertUtil.toString(param.get("baseUnit")), "1")) {
            qtOrderRowCol = qtOrderRowCol + ", NUMSCALETYPE DESC , NUMTYPE DESC";
        }

        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
            select_key_value_gt_zw_wd_bill_mx_sql_filed = " \t\t                ,NUMTYPE,NUMSCALETYPE,\n\t\t\t\t\t\tSUM(WD51) QCYE_SL,SUM(QCYE_HL) QCYE_DJ,\n\t\t\t\t\t\tSUM(WD52) SUM_J_SL,SUM(SUM_SL_J) SUM_J_DJ,\n\t\t\t\t\t\tSUM(WD53) SUM_D_SL,SUM(SUM_SL_D) SUM_D_DJ,\n\t\t\t\t\t\tSUM(WD54) QMYE_SL,SUM(QMYE_HL) QMYE_DJ,\n\t\t\t\t\t\tSUM(WD55) SUM_JL_SL,SUM(SUM_SL_JL) SUM_JL_DJ,\n\t\t\t\t\t\tSUM(WD56) SUM_DL_SL,SUM(SUM_SL_DL) SUM_DL_DJ ";
            select_key_value_sql_filed = " \t\t       ,NUMTYPE NUMTYPE,NUMSCALETYPE NUMSCALETYPE,\n\t\t       \tSUM(QCYE_SL) QCYE_SL,\n\t\t       \tCASE WHEN SUM(QCYE_SL) IS NULL OR SUM(QCYE_SL) = 0 THEN 0 WHEN SUM(QCYE_BWB) <> 0 AND SUM(QCYE_SL) <> 0 THEN SUM(QCYE_BWB)/SUM(QCYE_SL) ELSE SUM(QCYE_BWB) END  QCYE_DJ,\n\t\t\t\tSUM(SUM_J_SL) SUM_J_SL,\n\t\t       \tCASE WHEN SUM(SUM_J_SL) IS NULL OR SUM(SUM_J_SL) = 0 THEN 0 WHEN SUM(SUM_J) <> 0 AND SUM(SUM_J_SL) <> 0 THEN SUM(SUM_J)/SUM(SUM_J_SL) ELSE SUM(SUM_J) END  SUM_J_DJ,\n\t\t\t\tSUM(SUM_D_SL) SUM_D_SL,\n\t\t       \tCASE WHEN SUM(SUM_D_SL) IS NULL OR SUM(SUM_D_SL) = 0 THEN 0 WHEN SUM(SUM_D) <> 0 AND SUM(SUM_D_SL) <> 0 THEN SUM(SUM_D)/SUM(SUM_D_SL) ELSE SUM(SUM_D) END  SUM_D_DJ,\n\t\t\t\tSUM(QMYE_SL) QMYE_SL,\n\t\t       \tCASE WHEN SUM(QMYE_SL) IS NULL OR SUM(QMYE_SL) = 0 THEN 0 WHEN SUM(QMYE_BWB) <> 0 AND SUM(QMYE_SL) <> 0 THEN SUM(QMYE_BWB)/SUM(QMYE_SL) ELSE SUM(QMYE_BWB) END  QMYE_DJ,\n\t\t\t\tSUM(SUM_JL_SL) SUM_JL_SL,\n\t\t       \tCASE WHEN SUM(SUM_JL_SL) IS NULL OR SUM(SUM_JL_SL) = 0 THEN 0 WHEN SUM(SUM_JL) <> 0 AND SUM(SUM_JL_SL) <> 0 THEN SUM(SUM_JL)/SUM(SUM_JL_SL) ELSE SUM(SUM_JL) END  SUM_JL_DJ,\n\t\t\t\tSUM(SUM_DL_SL) SUM_DL_SL,\n\t\t       \tCASE WHEN SUM(SUM_DL_SL) IS NULL OR SUM(SUM_DL_SL) = 0 THEN 0 WHEN SUM(SUM_DL) <> 0 AND SUM(SUM_DL_SL) <> 0 THEN SUM(SUM_DL)/SUM(SUM_DL_SL) ELSE SUM(SUM_DL) END  SUM_DL_DJ ";
            select_key_value_sql_filed2 = "       \t\t       ,NUMTYPE,NUMSCALETYPE,\n\t\t       \tQCYE_SL,QCYE_DJ,\n\t\t\t\tSUM_J_SL,SUM_J_DJ,\n\t\t\t\tSUM_D_SL,SUM_D_DJ,\n\t\t\t\tQMYE_SL,QMYE_DJ,\n\t\t\t\tSUM_JL_SL,SUM_JL_DJ,\n\t\t\t\tSUM_DL_SL,SUM_DL_DJ ";
            group_by_add_num_type = ",NUMTYPE,NUMSCALETYPE ";
        }

        String kmRetrunFilterStr;
        String allMoney;
        if (isFromAccBalSum == 1 && !isShowAllWd || isShowAllWd && isShowAllWdHaveOrOneDim != null && isShowAllWdHaveOrOneDim == 0) {
            querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_HZ_TREE_QUERY_NO_DIM, compJoin, compCon, kmRetrunFilter, rollupRowCondition, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, rollupHaving, bzlx, select_key_value_gt_zw_wd_bill_mx_sql_filed, select_key_value_sql_filed, select_key_value_sql_filed2, group_by_add_num_type, bzxz, bzxzB, selectMxField, mxGroupByField, commaBUnitTotal, bUnitTotalComma, unitTotal, pUnitTotal);
            if (isForCur == 1) {
                kmRetrunFilterStr = "";
                allMoney = "";
                if (moneyType == -3) {
                    kmRetrunFilterStr = ",MONEY2";
                    allMoney = ",MONEY2 ASC";
                }

                querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_HZ_TREE_QUERY_FOR_CUR_NO_DIM, compJoin, compCon, kmRetrunFilter, rollupRowCondition, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, rollupHaving, bzlx, kmRetrunFilterStr, allMoney, select_key_value_gt_zw_wd_bill_mx_sql_filed, select_key_value_sql_filed, select_key_value_sql_filed2, group_by_add_num_type, bzxz, bzxzB, selectMxField, mxGroupByField, commaBUnitTotal, bUnitTotalComma, unitTotal, pUnitTotal);
            }
        } else if ((mxdwQuery == null || mxdwQuery != 1) && !isShowAllWd) {
            querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_HZ_TREE_QUERY, compJoin, compCon, kmRetrunFilter, rollupRowCondition, selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, rollupHaving, mysqlDimCol, select_key_value_gt_zw_wd_bill_mx_sql_filed, select_key_value_sql_filed, select_key_value_sql_filed2, group_by_add_num_type, selectMxField, mxGroupByField, levelRollUpWdCol, bUnitTotalComma, unitTotal, pUnitTotal);
            if (isForCur == 1) {
                kmRetrunFilterStr = "";
                allMoney = "";
                if (moneyType == -3) {
                    kmRetrunFilterStr = ",MONEY2";
                    allMoney = " , MONEY2 ASC ";
                }

                querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_HZ_TREE_QUERY_FOR_CUR, compJoin, compCon, kmRetrunFilter, rollupRowCondition, selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, rollupHaving, mysqlDimCol, kmRetrunFilterStr, allMoney, select_key_value_gt_zw_wd_bill_mx_sql_filed, select_key_value_sql_filed, select_key_value_sql_filed2, group_by_add_num_type, selectMxField, mxGroupByField, levelRollUpWdCol, bUnitTotalComma, unitTotal, pUnitTotal);
            }
        } else {
            kmRetrunFilterStr = kmRetrunFilter.replaceAll("WHERE", "AND");
            querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_HZ_TREE_QUERY_ONLY_DIM, compJoin, compCon, kmRetrunFilterStr, rollupRowCondition, selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, rollupHaving, bzlx, selectQtWdCol, select_key_value_gt_zw_wd_bill_mx_sql_filed, select_key_value_sql_filed, group_by_add_num_type, bzxz, bzxzB, selectMxField, mxGroupByField, xjmxCondition, bUnitTotalComma, xjmxHavinCondition);
            if (isForCur == 1) {
                allMoney = "";
                String orderByAllMoney = "";
                if (moneyType == -3) {
                    allMoney = ",MONEY2";
                    orderByAllMoney = " , MONEY2 ASC ";
                }

                querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_HZ_TREE_QUERY_ONLY_DIM_FOR_CUR, compJoin, compCon, kmRetrunFilterStr, rollupRowCondition, selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, rollupHaving, bzlx, allMoney, orderByAllMoney, selectQtWdCol, select_key_value_gt_zw_wd_bill_mx_sql_filed, select_key_value_sql_filed, group_by_add_num_type, bzxz, bzxzB, selectMxField, mxGroupByField, xjmxCondition, bUnitTotalComma, xjmxHavinCondition);
            }
        }

        querySql = AccComprehensiveQueryConvertSqlDao.selectKeyValueSql(querySql, param);
        querySql = AccComprehensiveQueryConvertSqlDao.convertSqlToSupportXjmxOrHzDataForIsShowAllWd(querySql, param);
        querySql = AccComprehensiveQueryConvertSqlDao.changeBeginBalanceSomeInfo(querySql, param);
        querySql = this.createAllKmTemp(param, querySql);
        return querySql;
    }

    public String createAllKmTemp(Map<String, Object> param, String querySql) {
        String allKmFindSql = querySql;
        if (ConvertUtil.toBoolean(param.get("isKmWdQuery")) && ConvertUtil.toInt(param.get("isFromAccBalSum")) == 1 && !ConvertUtil.toBoolean(param.get("isShowAllWd")) && StringUtils.equals("ALL", ConvertUtil.toString(param.get("dataType")))) {
            String compId = ConvertUtil.toString(param.get("selectcompid"));
            String unitControl = "'" + ConvertUtil.toString(param.get("unitControl")) + "'";
            String accBook = ConvertUtil.toString(param.get("accbookid"));
            String year = ConvertUtil.toString(param.get("accountYear"));
            String endAccount = ConvertUtil.toString(param.get("endAccount"));
            if (compId.contains(",")) {
                compId = " IN ('" + StringUtils.join(StringUtils.split(compId, ","), "','") + "') ";
            } else {
                compId = " = '" + compId + "' ";
            }

            Integer showStopKm = ConvertUtil.toInteger(param.get("isShowStopedKm"));
            String showStopKmSql = "";
            if (showStopKm == 0) {
                showStopKmSql = " AND A.IS_STOPED = 0 ";
            }

            String compLink = " AND B.COMPID = A.COMPID ";
            String groupComp = " A.COMPID, ";
            String compFile = ",B.FINA_ORG COMPID,B.SUPE_COMP_ID PCOMPID,B.FINA_ORG_NM DWMC,B.IS_BOTT_LAY COMPLEAF";
            String kmCompGroup = "";
            if (ConvertUtil.toBoolean(param.get("isShowByUnitTotal"))) {
                compLink = "";
                groupComp = "";
                compFile = "";
                kmCompGroup = "GROUP BY A.ITEM_CODE,  A.ACCO_CODE , A.SUB_FNAME , A.IS_BOTT_LAY , A.ACCO_LEVEL , A.ACC_SUB , DECODE(A.IS_BOTT_LAY, 1, 0, 1) , A.IS_STOPED  ";
            }

            try {
                Map<String, String> columnMap = this.getFindColumns(querySql);
                String findKmColumns = (String)columnMap.get("findKmColumns");
                String findColumn = (String)columnMap.get("findColumn");
                allKmFindSql = MessageFormat.format("SELECT {7} FROM (SELECT {6} FROM (\nSELECT\n\t{5} ACCOUNT_ID,{2} TYEAR,:KEY_VALUE KEY_VALUE ,A.ITEM_CODE KMITEMCODE,A.ACCO_CODE KMCODE,A.SUB_FNAME KMMC,A.IS_BOTT_LAY LEAF,A.ACCO_LEVEL ITEMLEVEL,A.ACC_SUB KMID,CASE A.IS_BOTT_LAY WHEN 1 THEN 0 ELSE 1 END ISKMDATA,A.IS_STOPED STOPED,'0' SUMMARY{11}\nFROM ACC_SUBJECT_EXT A,ACC_COMP_SCENE B\nWHERE A.ACC_BOOK = {1} AND A.FISC_YEA = {2} AND A.FINA_ORG = {8} {4}  AND A.ITEM_CODE IN ( SELECT ITEMCODE FROM GT_KMDESTTAB GROUP BY ITEMCODE)\n\tAND B.ORG_SCE_ID = ( SELECT ORG_SCE_ID FROM ACC_BOOK WHERE ACC_BOOK = {1} ) AND B.FINA_ORG {3} AND B.FISC_YEA = {2} {12}) A\nLEFT JOIN ({0}) B ON B.KMITEMCODE = A.KMITEMCODE {9}) A  ORDER BY {10} A.ACCOUNT_ID,A.KMCODE,A.ITEMLEVEL", querySql, accBook, year, compId, showStopKmSql, endAccount, findKmColumns, findColumn, unitControl, compLink, groupComp, compFile, kmCompGroup);
            } catch (Exception var18) {
                return querySql;
            }
        }

        if (DBUtil.isMySql()) {
            allKmFindSql = allKmFindSql.replaceAll("NVL", "IFNULL");
        }

        return allKmFindSql;
    }

    private Map<String, String> getFindColumns(String querySql) {
        Map<String, String> columnMap = new HashMap();
        String findColumns = "";
        String formattedSql = querySql.replace("\n", " ").replace("\r", " ");
        int fromIndex = formattedSql.toLowerCase().indexOf("from");
        if (fromIndex == -1) {
            throw new IllegalArgumentException("补全所有科目,sql未找到 'FROM'");
        } else {
            String selectPart = formattedSql.substring(formattedSql.indexOf("SELECT") + "select".length(), fromIndex).trim();
            String findColumn = selectPart.replaceAll("\\s*,\\s*", ",");
            findColumns = this.convertFields(findColumn);
            columnMap.put("findColumn", findColumn);
            columnMap.put("findKmColumns", findColumns);
            return columnMap;
        }
    }

    public String convertFields(String input) {
        StringBuilder result = new StringBuilder();
        String[] fields = input.split(",");
        String[] kmColArray = new String[]{"COMPID", "ACCOUNT_ID", "KMITEMCODE", "KMCODE", "KMMC", "LEAF", "ITEMLEVEL", "KMID", "ISKMDATA", "STOPED", "PCOMPID", "DWMC", "COMPLEAF"};
        String[] kmResColArray = new String[]{"KEY_VALUE", "TYEAR", "SUMMARY"};
        String[] resNvl0Array = new String[]{"QCYE_BWB", "JFJE_BWB", "DFJE_BWB", "QMYE_BWB", "JFJE_BWB_LJ", "DFJE_BWB_LJ", "QCYE", "JFJE", "DFJE", "QMYE", "JFJE_LJ", "DFJE_LJ", "SUM_J_BWB_YJZ", "SUM_D_BWB_YJZ", "SUM_JL_BWB_YJZ", "SUM_DL_BWB_YJZ", "SUM_J_BWB_WJZ", "SUM_D_BWB_WJZ", "QCYE_BWB_YJZ", "QMYE_BWB_YJZ"};
        String[] fxColArray = new String[]{"QCFX", "QMFX"};
        String[] var8 = fields;
        int var9 = fields.length;

        for(int var10 = 0; var10 < var9; ++var10) {
            String field = var8[var10];
            String column = field.split(" ")[0];
            if (Arrays.asList(kmColArray).contains(column)) {
                result.append("A.").append(column).append(' ').append(field).append(", ");
            } else if (Arrays.asList(kmResColArray).contains(column)) {
                result.append("NVL(B.").append(column).append(",A.").append(column).append(")").append(' ').append(field).append(", ");
            } else if (Arrays.asList(resNvl0Array).contains(column)) {
                result.append("NVL(B.").append(column).append(",0)").append(' ').append(field).append(", ");
            } else if (Arrays.asList(fxColArray).contains(column)) {
                result.append("NVL(B.").append(column).append(",'-')").append(' ').append(field).append(", ");
            } else {
                result.append("B.").append(field).append(", ");
            }
        }

        return result.toString().trim().replaceAll(",$", "");
    }

    private String getQuerySqlByGldx(String findTwoSql, Map<String, Object> param) {
        Integer isSelectDimValue = ConvertUtil.toInteger(param.get("isSelectDimValue"));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        Integer isSelectSubjectDim = ConvertUtil.toInteger(param.get("isSelectSubjectDim"));
        Integer moneyType = ConvertUtil.toInteger(param.get("moneyType"));
        String selectQtWdCol = ConvertUtil.toString(param.get("wdCol"));
        String dataTypeSumCondition = ConvertUtil.toString(param.get("dataTypeSumCondition"));
        String selectMxField = "";
        String mxGroupByField = "";
        if (this.isNcYe(param)) {
            selectMxField = ",SUM(QMYE_HL) QCYE_NC, SUM(QCYE_HL) QCYE_BWB_NC";
            mxGroupByField = "";
        }

        String qtRowCol = "";
        if (param.get("qtRowCol") != null) {
            qtRowCol = ConvertUtil.toString(param.get("qtRowCol"));
            if (mxdwQuery != null && mxdwQuery == 1 && isSelectDimValue != null && isSelectDimValue == 0) {
                qtRowCol = "";
            }
        }

        String qtGroupRowCol = "";
        if (param.get("qtGroupRowCol") != null) {
            qtGroupRowCol = ConvertUtil.toString(param.get("qtGroupRowCol"));
            if (mxdwQuery != null && mxdwQuery == 1 && isSelectDimValue != null && isSelectDimValue == 0) {
                qtGroupRowCol = "";
            }
        }

        String qtOrderRowCol = "";
        if (param.get("qtOrderRowCol") != null) {
            qtOrderRowCol = ConvertUtil.toString(param.get("qtOrderRowCol"));
            if (mxdwQuery != null && mxdwQuery == 1 && isSelectDimValue != null && isSelectDimValue == 0) {
                qtOrderRowCol = "";
            }
        }

        String companyinfo = ConvertUtil.toString(param.get("companyinfo"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String querySql = "";
        String kmRetrunFilter = " AND A.LEAF = 1 ";
        String compCol = ",C.PCOMPID, C.COMPNAME DWMC,C.LEAF COMPLEAF";
        String compJoin = ", (" + companyinfo + ") C";
        if (mxdwQuery != null && mxdwQuery == 1) {
            compJoin = ", " + companyinfo + " C";
        }

        String compCon = "  AND B.COMPID = C.COMPID ";
        String compGroup = ", C.PCOMPID,C.COMPNAME,C.LEAF";
        String orderByATableCol;
        if (mxdwQuery == null || mxdwQuery == 0) {
            Integer isExport = ConvertUtil.toInteger(param.get("isExport"));
            if (isExport == 0) {
                orderByATableCol = ConvertUtil.toString(param.get("compname"));
                compCol = ",'0' PCOMPID, '" + orderByATableCol + "' AS DWMC,1 AS COMPLEAF";
                compJoin = "";
                compCon = "";
                compGroup = "";
            }
        }

        String groupByATableCol = ", A.FLGID, A.ITEMCODE, A.LEAF";
        orderByATableCol = ", A.ITEMCODE,MAX(A.ITEMLEVEL)";
        String selectATableCol = ",A.ITEMCODE KMITEMCODE, MAX(A.CODE) KMCODE, MAX(A.CAPTION) KMMC,MAX(A.LEAF) LEAF, MAX(A.ITEMLEVEL) ITEMLEVEL, MAX(A.FLGID) KMID,DECODE( A.LEAF, 1, 0, 1) ISKMDATA,MAX(A.STOPED) STOPED";
        if (DBUtil.isMySql()) {
            selectATableCol = ",A.ITEMCODE KMITEMCODE, MAX(A.CODE) KMCODE, MAX(A.CAPTION) KMMC,MAX(A.LEAF) LEAF, MAX(A.ITEMLEVEL) ITEMLEVEL, MAX(A.FLGID) KMID, (CASE A.LEAF WHEN 1 THEN 0 ELSE 1 END) ISKMDATA,MAX(A.STOPED) STOPED";
        }

        if (isSelectSubjectDim != 1) {
            if (DBUtil.isMySql()) {
                selectATableCol = " ,'' KMITEMCODE, '' KMCODE, '' KMMC,1 LEAF, 0 ITEMLEVEL, 0 KMID, 0 ISKMDATA,0 STOPED";
            } else {
                selectATableCol = " ,NULL KMITEMCODE, NULL KMCODE, NULL KMMC,1 LEAF, NULL ITEMLEVEL, NULL KMID, 0 ISKMDATA,NULL STOPED";
            }

            groupByATableCol = ", A.LEAF";
            orderByATableCol = "";
        }

        String bzlx = "";
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        if ("MERGEDATA".equals(dataOption) && mxdwQuery != null && mxdwQuery == 1) {
            bzlx = " ,BZLX ";
            compGroup = ", C.PCOMPID,C.COMPNAME,C.LEAF, B.BZLX ";
            compCol = ", C.PCOMPID,CASE COALESCE(B.bzlx,0) WHEN 1 THEN CONCAT(COALESCE(C.COMPNAME, ''),'抵销账') ELSE C.COMPNAME END DWMC,C.LEAF COMPLEAF";
        }

        if (StringUtils.equals(ConvertUtil.toString(param.get("baseUnit")), "1")) {

            qtOrderRowCol = qtOrderRowCol + ", NUMSCALETYPE DESC , NUMTYPE DESC";
        }

        querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_OBJECT_HZ_TREE_QUERY, compJoin, compCon, " AND A.LEAF = 1 ", "", selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, selectATableCol, groupByATableCol, orderByATableCol, dataTypeSumCondition, bzlx, "", "", "", selectMxField, mxGroupByField);
        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
            querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_OBJECT_HZ_TREE_QUERY, compJoin, compCon, " AND A.LEAF = 1 ", "", selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, selectATableCol, groupByATableCol, orderByATableCol, dataTypeSumCondition, bzlx, " \t\t                ,NUMTYPE,NUMSCALETYPE,\n\t\t\t\t\t\tSUM(WD51) QCYE_SL,SUM(QCYE_HL) QCYE_DJ,\n\t\t\t\t\t\tSUM(WD52) SUM_J_SL,SUM(SUM_SL_J) SUM_J_DJ,\n\t\t\t\t\t\tSUM(WD53) SUM_D_SL,SUM(SUM_SL_D) SUM_D_DJ,\n\t\t\t\t\t\tSUM(WD54) QMYE_SL,SUM(QMYE_HL) QMYE_DJ,\n\t\t\t\t\t\tSUM(WD55) SUM_JL_SL,SUM(SUM_SL_JL) SUM_JL_DJ,\n\t\t\t\t\t\tSUM(WD56) SUM_DL_SL,SUM(SUM_SL_DL) SUM_DL_DJ ", " \t\t       ,NUMTYPE NUMTYPE,NUMSCALETYPE NUMSCALETYPE,\n\t\t       \tSUM(QCYE_SL) QCYE_SL,\n\t\t       \tCASE WHEN SUM(QCYE_SL) IS NULL OR SUM(QCYE_SL) = 0 THEN 0 WHEN SUM(QCYE_BWB) <> 0 AND SUM(QCYE_SL) <> 0 THEN SUM(QCYE_BWB)/SUM(QCYE_SL) ELSE SUM(QCYE_BWB) END  QCYE_DJ,\n\t\t\t\tSUM(SUM_J_SL) SUM_J_SL,\n\t\t       \tCASE WHEN SUM(SUM_J_SL) IS NULL OR SUM(SUM_J_SL) = 0 THEN 0 WHEN SUM(SUM_J) <> 0 AND SUM(SUM_J_SL) <> 0 THEN SUM(SUM_J)/SUM(SUM_J_SL) ELSE SUM(SUM_J) END  SUM_J_DJ,\n\t\t\t\tSUM(SUM_D_SL) SUM_D_SL,\n\t\t       \tCASE WHEN SUM(SUM_D_SL) IS NULL OR SUM(SUM_D_SL) = 0 THEN 0 WHEN SUM(SUM_D) <> 0 AND SUM(SUM_D_SL) <> 0 THEN SUM(SUM_D)/SUM(SUM_D_SL) ELSE SUM(SUM_D) END  SUM_D_DJ,\n\t\t\t\tSUM(QMYE_SL) QMYE_SL,\n\t\t       \tCASE WHEN SUM(QMYE_SL) IS NULL OR SUM(QMYE_SL) = 0 THEN 0 WHEN SUM(QMYE_BWB) <> 0 AND SUM(QMYE_SL) <> 0 THEN SUM(QMYE_BWB)/SUM(QMYE_SL) ELSE SUM(QMYE_BWB) END  QMYE_DJ,\n\t\t\t\tSUM(SUM_JL_SL) SUM_JL_SL,\n\t\t       \tCASE WHEN SUM(SUM_JL_SL) IS NULL OR SUM(SUM_JL_SL) = 0 THEN 0 WHEN SUM(SUM_JL) <> 0 AND SUM(SUM_JL_SL) <> 0 THEN SUM(SUM_JL)/SUM(SUM_JL_SL) ELSE SUM(SUM_JL) END  SUM_JL_DJ,\n\t\t\t\tSUM(SUM_DL_SL) SUM_DL_SL,\n\t\t       \tCASE WHEN SUM(SUM_DL_SL) IS NULL OR SUM(SUM_DL_SL) = 0 THEN 0 WHEN SUM(SUM_DL) <> 0 AND SUM(SUM_DL_SL) <> 0 THEN SUM(SUM_DL)/SUM(SUM_DL_SL) ELSE SUM(SUM_DL) END  SUM_DL_DJ ", ",NUMTYPE,NUMSCALETYPE ", selectMxField, mxGroupByField);
        }

        if (isForCur == 1) {
            String orderByAllMoney = "";
            String allMoney = "";
            if (moneyType == -3) {
                allMoney = ",MONEY2";
                orderByAllMoney = " , MONEY2 ASC ";
            }

            querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_OBJECT_HZ_TREE_QUERY_FOR_CUR, compJoin, compCon, " AND A.LEAF = 1 ", "", selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, selectATableCol, groupByATableCol, orderByATableCol, dataTypeSumCondition, bzlx, allMoney, "", "", "", orderByAllMoney, selectMxField, mxGroupByField);
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_OBJECT_HZ_TREE_QUERY_FOR_CUR, compJoin, compCon, " AND A.LEAF = 1 ", "", selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, selectATableCol, groupByATableCol, orderByATableCol, dataTypeSumCondition, bzlx, allMoney, " \t\t                ,NUMTYPE,NUMSCALETYPE,\n\t\t\t\t\t\tSUM(WD51) QCYE_SL,SUM(QCYE_HL) QCYE_DJ,\n\t\t\t\t\t\tSUM(WD52) SUM_J_SL,SUM(SUM_SL_J) SUM_J_DJ,\n\t\t\t\t\t\tSUM(WD53) SUM_D_SL,SUM(SUM_SL_D) SUM_D_DJ,\n\t\t\t\t\t\tSUM(WD54) QMYE_SL,SUM(QMYE_HL) QMYE_DJ,\n\t\t\t\t\t\tSUM(WD55) SUM_JL_SL,SUM(SUM_SL_JL) SUM_JL_DJ,\n\t\t\t\t\t\tSUM(WD56) SUM_DL_SL,SUM(SUM_SL_DL) SUM_DL_DJ ", " \t\t       ,NUMTYPE NUMTYPE,NUMSCALETYPE NUMSCALETYPE,\n\t\t       \tSUM(QCYE_SL) QCYE_SL,\n\t\t       \tCASE WHEN SUM(QCYE_SL) IS NULL OR SUM(QCYE_SL) = 0 THEN 0 WHEN SUM(QCYE_BWB) <> 0 AND SUM(QCYE_SL) <> 0 THEN SUM(QCYE_BWB)/SUM(QCYE_SL) ELSE SUM(QCYE_BWB) END  QCYE_DJ,\n\t\t\t\tSUM(SUM_J_SL) SUM_J_SL,\n\t\t       \tCASE WHEN SUM(SUM_J_SL) IS NULL OR SUM(SUM_J_SL) = 0 THEN 0 WHEN SUM(SUM_J) <> 0 AND SUM(SUM_J_SL) <> 0 THEN SUM(SUM_J)/SUM(SUM_J_SL) ELSE SUM(SUM_J) END  SUM_J_DJ,\n\t\t\t\tSUM(SUM_D_SL) SUM_D_SL,\n\t\t       \tCASE WHEN SUM(SUM_D_SL) IS NULL OR SUM(SUM_D_SL) = 0 THEN 0 WHEN SUM(SUM_D) <> 0 AND SUM(SUM_D_SL) <> 0 THEN SUM(SUM_D)/SUM(SUM_D_SL) ELSE SUM(SUM_D) END  SUM_D_DJ,\n\t\t\t\tSUM(QMYE_SL) QMYE_SL,\n\t\t       \tCASE WHEN SUM(QMYE_SL) IS NULL OR SUM(QMYE_SL) = 0 THEN 0 WHEN SUM(QMYE_BWB) <> 0 AND SUM(QMYE_SL) <> 0 THEN SUM(QMYE_BWB)/SUM(QMYE_SL) ELSE SUM(QMYE_BWB) END  QMYE_DJ,\n\t\t\t\tSUM(SUM_JL_SL) SUM_JL_SL,\n\t\t       \tCASE WHEN SUM(SUM_JL_SL) IS NULL OR SUM(SUM_JL_SL) = 0 THEN 0 WHEN SUM(SUM_JL) <> 0 AND SUM(SUM_JL_SL) <> 0 THEN SUM(SUM_JL)/SUM(SUM_JL_SL) ELSE SUM(SUM_JL) END  SUM_JL_DJ,\n\t\t\t\tSUM(SUM_DL_SL) SUM_DL_SL,\n\t\t       \tCASE WHEN SUM(SUM_DL_SL) IS NULL OR SUM(SUM_DL_SL) = 0 THEN 0 WHEN SUM(SUM_DL) <> 0 AND SUM(SUM_DL_SL) <> 0 THEN SUM(SUM_DL)/SUM(SUM_DL_SL) ELSE SUM(SUM_DL) END  SUM_DL_DJ ", ",NUMTYPE,NUMSCALETYPE ", orderByAllMoney, selectMxField, mxGroupByField);
            }
        }

        querySql = AccComprehensiveQueryConvertSqlDao.selectKeyValueSql(querySql, param);
        querySql = AccComprehensiveQueryConvertSqlDao.changeBeginBalanceSomeInfo(querySql, param);
        return querySql;
    }

    private String getQuerySqlByYwfl(String findTwoSql, Map<String, Object> param) {
        String wdAndClsCon = this.buildFlTreeTempTable(param);
        Integer isOneDimQuery = ConvertUtil.toInteger(param.get("isOneDimQuery"));
        Integer isSelectDimValue = ConvertUtil.toInteger(param.get("isSelectDimValue"));
        Integer mxdwQuery = ConvertUtil.toInteger(param.get("mxdwQuery"));
        Integer isSelectSubjectDim = ConvertUtil.toInteger(param.get("isSelectSubjectDim"));
        String selectQtWdCol = ConvertUtil.toString(param.get("wdCol"));
        String dataTypeSumCondition = ConvertUtil.toString(param.get("dataTypeSumCondition"));
        int moneyType = ConvertUtil.toInt(param.get("moneyType"));
        String selectMxField = "";
        String mxGroupByField = "";
        if (this.isNcYe(param)) {
            selectMxField = ",SUM(QMYE_HL) QCYE_NC, SUM(QCYE_HL) QCYE_BWB_NC";
            mxGroupByField = "";
        }

        String qtRowCol = "";
        if (param.get("qtRowCol") != null) {
            qtRowCol = ConvertUtil.toString(param.get("qtRowCol"));
            if (mxdwQuery != null && mxdwQuery == 1 && isSelectDimValue != null && isSelectDimValue == 0) {
                qtRowCol = "";
            }
        }

        String qtGroupRowCol = "";
        if (param.get("qtGroupRowCol") != null) {
            qtGroupRowCol = ConvertUtil.toString(param.get("qtGroupRowCol"));
            if (mxdwQuery != null && mxdwQuery == 1 && isSelectDimValue != null && isSelectDimValue == 0) {
                qtGroupRowCol = "";
            }
        }

        String qtOrderRowCol = "";
        if (param.get("qtOrderRowCol") != null) {
            qtOrderRowCol = ConvertUtil.toString(param.get("qtOrderRowCol"));
            if (mxdwQuery != null && mxdwQuery == 1 && isSelectDimValue != null && isSelectDimValue == 0) {
                qtOrderRowCol = "";
            }
        }

        String companyinfo = ConvertUtil.toString(param.get("companyinfo"));
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String rollupRow = "";
        String querySql = "";
        String kmRetrunFilter = " AND A.LEAF = 1 ";
        String compCol = ",C.PCOMPID, C.COMPNAME DWMC,C.LEAF COMPLEAF";
        String compJoin = ", (" + companyinfo + ") C";
        if (mxdwQuery != null && mxdwQuery == 1) {
            compJoin = ", " + companyinfo + " C";
        }

        String compCon = "  AND B.COMPID = C.COMPID ";
        String compGroup = ", C.PCOMPID,C.COMPNAME,C.LEAF";
        String orderByATableCol;
        if (mxdwQuery == null || mxdwQuery == 0) {
            Integer isExport = ConvertUtil.toInteger(param.get("isExport"));
            if (isExport == 0) {
                orderByATableCol = ConvertUtil.toString(param.get("compname"));
                compCol = ",'0' PCOMPID, '" + orderByATableCol + "' AS DWMC,1 AS COMPLEAF";
                compJoin = "";
                compCon = "";
                compGroup = "";
            }
        }

        String groupByATableCol = ", A.FLGID, A.ITEMCODE, A.LEAF";
        orderByATableCol = ", A.ITEMCODE,MAX(A.ITEMLEVEL)";
        String selectATableCol = ",A.ITEMCODE KMITEMCODE, MAX(A.CODE) KMCODE, MAX(A.CAPTION) KMMC,MAX(A.LEAF) LEAF, MAX(A.ITEMLEVEL) ITEMLEVEL, MAX(A.FLGID) KMID,DECODE( A.LEAF, 1, 0, 1) ISKMDATA,MAX(A.STOPED) STOPED";
        if (DBUtil.isMySql()) {
            selectATableCol = ",A.ITEMCODE KMITEMCODE, MAX(A.CODE) KMCODE, MAX(A.CAPTION) KMMC,MAX(A.LEAF) LEAF, MAX(A.ITEMLEVEL) ITEMLEVEL, MAX(A.FLGID) KMID,(CASE A.LEAF WHEN 1 THEN 0 ELSE 1 END) ISKMDATA,MAX(A.STOPED) STOPED";
        }

        if (isSelectSubjectDim != 1) {
            if (DBUtil.isMySql()) {
                selectATableCol = " ,'' KMITEMCODE, '' KMCODE, '' KMMC,1 LEAF, 0 ITEMLEVEL, 0 KMID, (CASE D.LEAF WHEN 1 THEN 0 ELSE 1 END) ISKMDATA,0 STOPED";
            } else {
                selectATableCol = " ,NULL KMITEMCODE, NULL KMCODE, NULL KMMC,1 LEAF, NULL ITEMLEVEL, NULL KMID, DECODE( D.LEAF, 1, 0, 1) ISKMDATA,NULL STOPED";
            }

            groupByATableCol = ", A.LEAF, D.LEAF";
            orderByATableCol = "";
        }

        boolean isOneDim = param.get("isYwMainAndOneDim") != null && ConvertUtil.toInt(param.get("isYwMainAndOneDim")) == 1;
        if (isOneDim) {
            groupByATableCol = ", D.LEAF";
            kmRetrunFilter = "";
            compCon = " B.COMPID = C.COMPID ";
            qtRowCol = "";
            qtGroupRowCol = "";
        } else {
            qtGroupRowCol = qtGroupRowCol.replaceAll("''", "");
        }

        String ywflLeaf = " AND D.LEAF = 1";
        if (isOneDimQuery != null && isOneDimQuery == 1 && isSelectSubjectDim == 0 && (mxdwQuery == null || mxdwQuery == 0)) {
            ywflLeaf = "";
            dataTypeSumCondition = "";
        }

        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        String bzlx = "";
        if ("MERGEDATA".equals(dataOption) && mxdwQuery != null && mxdwQuery == 1) {
            bzlx = " ,BZLX ";
            compGroup = ", C.PCOMPID,C.COMPNAME,C.LEAF, B.BZLX ";
            compCol = ", C.PCOMPID,CASE COALESCE(B.bzlx,0) WHEN 1 THEN CONCAT(COALESCE(C.COMPNAME, ''),'抵销账') ELSE C.COMPNAME END DWMC,C.LEAF COMPLEAF";
        }

        if (StringUtils.equals(ConvertUtil.toString(param.get("baseUnit")), "1")) {

            qtOrderRowCol = qtOrderRowCol + ", NUMSCALETYPE DESC , NUMTYPE DESC";
        }

        querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_BUS_CLASS_HZ_TREE_QUERY, compJoin, compCon, kmRetrunFilter, wdAndClsCon, selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, selectATableCol, groupByATableCol, orderByATableCol, ywflLeaf, dataTypeSumCondition, bzlx, "", "", "", selectMxField, mxGroupByField);
        if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
            querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_BUS_CLASS_HZ_TREE_QUERY, compJoin, compCon, kmRetrunFilter, wdAndClsCon, selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, selectATableCol, groupByATableCol, orderByATableCol, ywflLeaf, dataTypeSumCondition, bzlx, " \t\t                ,NUMTYPE,NUMSCALETYPE,\n\t\t\t\t\t\tSUM(WD51) QCYE_SL,SUM(QCYE_HL) QCYE_DJ,\n\t\t\t\t\t\tSUM(WD52) SUM_J_SL,SUM(SUM_SL_J) SUM_J_DJ,\n\t\t\t\t\t\tSUM(WD53) SUM_D_SL,SUM(SUM_SL_D) SUM_D_DJ,\n\t\t\t\t\t\tSUM(WD54) QMYE_SL,SUM(QMYE_HL) QMYE_DJ,\n\t\t\t\t\t\tSUM(WD55) SUM_JL_SL,SUM(SUM_SL_JL) SUM_JL_DJ,\n\t\t\t\t\t\tSUM(WD56) SUM_DL_SL,SUM(SUM_SL_DL) SUM_DL_DJ ", " \t\t       ,NUMTYPE NUMTYPE,NUMSCALETYPE NUMSCALETYPE,\n\t\t       \tSUM(QCYE_SL) QCYE_SL,\n\t\t       \tCASE WHEN SUM(QCYE_SL) IS NULL OR SUM(QCYE_SL) = 0 THEN 0 WHEN SUM(QCYE_BWB) <> 0 AND SUM(QCYE_SL) <> 0 THEN SUM(QCYE_BWB)/SUM(QCYE_SL) ELSE SUM(QCYE_BWB) END  QCYE_DJ,\n\t\t\t\tSUM(SUM_J_SL) SUM_J_SL,\n\t\t       \tCASE WHEN SUM(SUM_J_SL) IS NULL OR SUM(SUM_J_SL) = 0 THEN 0 WHEN SUM(SUM_J) <> 0 AND SUM(SUM_J_SL) <> 0 THEN SUM(SUM_J)/SUM(SUM_J_SL) ELSE SUM(SUM_J) END  SUM_J_DJ,\n\t\t\t\tSUM(SUM_D_SL) SUM_D_SL,\n\t\t       \tCASE WHEN SUM(SUM_D_SL) IS NULL OR SUM(SUM_D_SL) = 0 THEN 0 WHEN SUM(SUM_D) <> 0 AND SUM(SUM_D_SL) <> 0 THEN SUM(SUM_D)/SUM(SUM_D_SL) ELSE SUM(SUM_D) END  SUM_D_DJ,\n\t\t\t\tSUM(QMYE_SL) QMYE_SL,\n\t\t       \tCASE WHEN SUM(QMYE_SL) IS NULL OR SUM(QMYE_SL) = 0 THEN 0 WHEN SUM(QMYE_BWB) <> 0 AND SUM(QMYE_SL) <> 0 THEN SUM(QMYE_BWB)/SUM(QMYE_SL) ELSE SUM(QMYE_BWB) END  QMYE_DJ,\n\t\t\t\tSUM(SUM_JL_SL) SUM_JL_SL,\n\t\t       \tCASE WHEN SUM(SUM_JL_SL) IS NULL OR SUM(SUM_JL_SL) = 0 THEN 0 WHEN SUM(SUM_JL) <> 0 AND SUM(SUM_JL_SL) <> 0 THEN SUM(SUM_JL)/SUM(SUM_JL_SL) ELSE SUM(SUM_JL) END  SUM_JL_DJ,\n\t\t\t\tSUM(SUM_DL_SL) SUM_DL_SL,\n\t\t       \tCASE WHEN SUM(SUM_DL_SL) IS NULL OR SUM(SUM_DL_SL) = 0 THEN 0 WHEN SUM(SUM_DL) <> 0 AND SUM(SUM_DL_SL) <> 0 THEN SUM(SUM_DL)/SUM(SUM_DL_SL) ELSE SUM(SUM_DL) END  SUM_DL_DJ ", ",NUMTYPE,NUMSCALETYPE ", selectMxField, mxGroupByField);
        }

        String allMoney;
        String orderByAllMoney;
        if (isForCur == 1) {
            allMoney = "";
            orderByAllMoney = "";
            if (moneyType == -3) {
                allMoney = ",MONEY2";
                orderByAllMoney = " , MONEY2 ASC ";
            }

            querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_BUS_CLASS_HZ_TREE_QUERY_FOR_CUR, compJoin, compCon, kmRetrunFilter, wdAndClsCon, selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, selectATableCol, groupByATableCol, orderByATableCol, ywflLeaf, dataTypeSumCondition, bzlx, allMoney, orderByAllMoney, "", "", "", selectMxField, mxGroupByField);
            if (StringUtils.equals(ConvertUtil.toString(param.get("dataStyle")), "2")) {
                querySql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_KM_BUS_CLASS_HZ_TREE_QUERY_FOR_CUR, compJoin, compCon, kmRetrunFilter, wdAndClsCon, selectQtWdCol, selectQtWdCol, qtRowCol, compCol, compGroup, qtGroupRowCol, qtOrderRowCol, selectATableCol, groupByATableCol, orderByATableCol, ywflLeaf, dataTypeSumCondition, bzlx, allMoney, orderByAllMoney, " \t\t                ,NUMTYPE,NUMSCALETYPE,\n\t\t\t\t\t\tSUM(WD51) QCYE_SL,SUM(QCYE_HL) QCYE_DJ,\n\t\t\t\t\t\tSUM(WD52) SUM_J_SL,SUM(SUM_SL_J) SUM_J_DJ,\n\t\t\t\t\t\tSUM(WD53) SUM_D_SL,SUM(SUM_SL_D) SUM_D_DJ,\n\t\t\t\t\t\tSUM(WD54) QMYE_SL,SUM(QMYE_HL) QMYE_DJ,\n\t\t\t\t\t\tSUM(WD55) SUM_JL_SL,SUM(SUM_SL_JL) SUM_JL_DJ,\n\t\t\t\t\t\tSUM(WD56) SUM_DL_SL,SUM(SUM_SL_DL) SUM_DL_DJ ", " \t\t       ,NUMTYPE NUMTYPE,NUMSCALETYPE NUMSCALETYPE,\n\t\t       \tSUM(QCYE_SL) QCYE_SL,\n\t\t       \tCASE WHEN SUM(QCYE_SL) IS NULL OR SUM(QCYE_SL) = 0 THEN 0 WHEN SUM(QCYE_BWB) <> 0 AND SUM(QCYE_SL) <> 0 THEN SUM(QCYE_BWB)/SUM(QCYE_SL) ELSE SUM(QCYE_BWB) END  QCYE_DJ,\n\t\t\t\tSUM(SUM_J_SL) SUM_J_SL,\n\t\t       \tCASE WHEN SUM(SUM_J_SL) IS NULL OR SUM(SUM_J_SL) = 0 THEN 0 WHEN SUM(SUM_J) <> 0 AND SUM(SUM_J_SL) <> 0 THEN SUM(SUM_J)/SUM(SUM_J_SL) ELSE SUM(SUM_J) END  SUM_J_DJ,\n\t\t\t\tSUM(SUM_D_SL) SUM_D_SL,\n\t\t       \tCASE WHEN SUM(SUM_D_SL) IS NULL OR SUM(SUM_D_SL) = 0 THEN 0 WHEN SUM(SUM_D) <> 0 AND SUM(SUM_D_SL) <> 0 THEN SUM(SUM_D)/SUM(SUM_D_SL) ELSE SUM(SUM_D) END  SUM_D_DJ,\n\t\t\t\tSUM(QMYE_SL) QMYE_SL,\n\t\t       \tCASE WHEN SUM(QMYE_SL) IS NULL OR SUM(QMYE_SL) = 0 THEN 0 WHEN SUM(QMYE_BWB) <> 0 AND SUM(QMYE_SL) <> 0 THEN SUM(QMYE_BWB)/SUM(QMYE_SL) ELSE SUM(QMYE_BWB) END  QMYE_DJ,\n\t\t\t\tSUM(SUM_JL_SL) SUM_JL_SL,\n\t\t       \tCASE WHEN SUM(SUM_JL_SL) IS NULL OR SUM(SUM_JL_SL) = 0 THEN 0 WHEN SUM(SUM_JL) <> 0 AND SUM(SUM_JL_SL) <> 0 THEN SUM(SUM_JL)/SUM(SUM_JL_SL) ELSE SUM(SUM_JL) END  SUM_JL_DJ,\n\t\t\t\tSUM(SUM_DL_SL) SUM_DL_SL,\n\t\t       \tCASE WHEN SUM(SUM_DL_SL) IS NULL OR SUM(SUM_DL_SL) = 0 THEN 0 WHEN SUM(SUM_DL) <> 0 AND SUM(SUM_DL_SL) <> 0 THEN SUM(SUM_DL)/SUM(SUM_DL_SL) ELSE SUM(SUM_DL) END  SUM_DL_DJ ", ",NUMTYPE,NUMSCALETYPE ", selectMxField, mxGroupByField);
            }
        }

        if (isOneDim) {
            allMoney = "GT_KMDESTTAB A,";
            orderByAllMoney = "A.IID = B.KMID";
            querySql = querySql.replace(allMoney, "");
            querySql = querySql.replace(orderByAllMoney, "");
        }

        querySql = AccComprehensiveQueryConvertSqlDao.selectKeyValueSql(querySql, param);
        querySql = AccComprehensiveQueryConvertSqlDao.changeBeginBalanceSomeInfo(querySql, param);
        return querySql;
    }

    private String buildFlTreeTempTable(Map<String, Object> queryParam) {
        String queryModel = ConvertUtil.toString(queryParam.get("queryModel"));
        StringBuilder wdAndClsCon = new StringBuilder("");
        StringBuilder itemCodeContion = new StringBuilder(" AND (");
        String compId = ConvertUtil.toString(queryParam.get("unitControl"));
        String accountYear = ConvertUtil.toString(queryParam.get("accountYear"));
        Map<String, Object> params = new HashMap();
        params.put("TYEAR", accountYear);
        params.put("COMPID", compId);
        String itemCode = "";
        String sql;
        if ("1".equals(queryModel)) {
            itemCode = ConvertUtil.toString(queryParam.get("collectItemCodes"));
            String collectWdCol = ConvertUtil.toString(queryParam.get("collectWdCol"));
            String[] collectWdCols = collectWdCol.split(",");
            wdAndClsCon.append(" AND (");

            for(int i = 0; i < collectWdCols.length; ++i) {
                if (i != 0) {
                    wdAndClsCon.append(" OR ");
                }

                wdAndClsCon.append(" B.");
                wdAndClsCon.append(collectWdCols[i]);
                wdAndClsCon.append(" = D.IID ");
            }

            wdAndClsCon.append(")");
        } else {
            Map<String, Object> flitemcode = (Map)queryParam.get("flitemcode");
            String wdName = ConvertUtil.toString(flitemcode.get("wdname"));
            wdAndClsCon.append(" AND B." + wdName + " = D.IID ");
            if (flitemcode.get("selvalue") != null && !StringUtils.isEmpty(ConvertUtil.toString(flitemcode.get("selvalue")))) {
                sql = ConvertUtil.toString(flitemcode.get("selvalue"));
                itemCode = sql;
            } else {
                itemCode = ConvertUtil.toString(flitemcode.get("lxid"));
            }
        }

        String[] itemCodes = itemCode.split(",");
        int length = itemCodes.length;

        for(int i = 0; i < length; ++i) {
            if (i != 0) {
                itemCodeContion.append(" OR ");
            }

            itemCodeContion.append(" ITEMCODE LIKE '");
            itemCodeContion.append(itemCodes[i]);
            itemCodeContion.append("%'");
        }

        itemCodeContion.append(" )");
        sql = MessageFormat.format(AccComprehensiveQueryDaoConst.DW_FL_TREE_RELATION, itemCodeContion.toString());
        log.info(sql);
        return wdAndClsCon.toString();
    }

    public String bulidDwHzResultTable(String findTwoSql, Map<String, Object> param) {
        String sql = "";
        String maintype = ConvertUtil.toString(param.get("mainType"));
        if ("2".equals(maintype)) {
            sql = this.getQuerySqlByKm(findTwoSql, param);
        } else if ("0".equals(maintype)) {
            sql = this.getQuerySqlByGldx(findTwoSql, param);
        } else if ("1".equals(maintype)) {
            sql = this.getQuerySqlByYwfl(findTwoSql, param);
        }

        return sql;
    }


    private void analyzeCollectYwfl(Map<String, Object> param) {
        List<Map<String, Object>> selectWd = (List)param.get("classifyUseWd");
        StringBuilder collectItemCodes = new StringBuilder("");
        StringBuilder collectWdCol = new StringBuilder("");
        int isCollectBusCla = 0;
        Iterator var6 = selectWd.iterator();

        while(var6.hasNext()) {
            Map<String, Object> wdObj = (Map)var6.next();
            String curWdname = ConvertUtil.toString(wdObj.get("wdname"));
            if (StringUtils.isNotEmpty(curWdname)) {
                String type = ConvertUtil.toString(wdObj.get("type"));
                if (!"2".equals(type)) {
                    String curWdlxid = ConvertUtil.toString(wdObj.get("lxid"));
                    int isCollect = ConvertUtil.toInt(wdObj.get("wdcollect"));
                    if (isCollect == 1) {
                        isCollectBusCla = 1;
                        if (StringUtils.isNotEmpty(collectItemCodes.toString())) {
                            collectItemCodes.append(",").append(curWdlxid);
                            collectWdCol.append(",").append(curWdname);
                        } else {
                            collectItemCodes.append(curWdlxid);
                            collectWdCol.append(curWdname);
                        }
                    }
                }
            }
        }

        param.put("collectItemCodes", collectItemCodes.toString());
        param.put("collectWdCol", collectWdCol.toString());
        param.put("isCollectBusCla", Integer.valueOf(isCollectBusCla));
    }

    public String buildDwKmInfoHzTempTable(Map<String, Object> param) {
        this.analyzeParamPro(param);
        String findOneSql = this.buildFindSqlFromSoureTable(param);
        String findLimitFindOneSql = this.limitHzDataForHzTempTable(param, findOneSql);
        String findTwoSql = this.buildTempTableInGt(param, findLimitFindOneSql);
        return findTwoSql;
    }

    public String buildDwKmInfoHzTempTablePro(Map<String, Object> param) {
        Map<String, Object> beginBalanceParam = (Map)param.get("beginBalanceParam");
        param.put("hasAnalyze", false);
        if (!Objects.isNull(beginBalanceParam) && !beginBalanceParam.isEmpty()) {
            this.analyzeParam(beginBalanceParam);
            param.put("hasAnalyze", true);
            String findOneSql = this.buildFindSqlFromSoureTable(beginBalanceParam);
            String findLimitFindOneSql = this.limitHzDataForHzTempTable(beginBalanceParam, findOneSql);
            this.buildTempTableInGt(beginBalanceParam, findLimitFindOneSql);
            this.handJanuaryDataOfWdBillMxTable(param, 1);
        }
        String findTwoSql = this.buildDwKmInfoHzTempTable(param);
        this.handJanuaryDataOfWdBillMxTable(param, 2);
        return findTwoSql;
    }

    private void handJanuaryDataOfWdBillMxTable(Map<String, Object> param, int step) {
        AccConditionUtils.isAllMatch(new Boolean[]{this.isNcYe(param)}).handleCondition(() -> {
            AccConditionUtils.isAllMatch(new Boolean[]{step == 1}).handleCondition(() -> {
                Map<String, Object> beginBalanceParam = (Map)param.get("beginBalanceParam");
                String deleteSql = "UPDATE GT_ZW_WDBILLMX SET TYPEBZ = 1 WHERE ACCOUNT_ID = " + beginBalanceParam.get("beginAccount");
                log.info(deleteSql);
            });
            AccConditionUtils.isAllMatch(new Boolean[]{step == 2}).handleCondition(() -> {
                this.handJanuaryDataOfWdBillMxTableForOneDimYwMain(param);
                int moneyType = ConvertUtil.toInt(param.get("moneyType"));
                String selectField = "";
                String insertField = "";
                String condition = "";
                if (moneyType == -3) {
                    condition = "AND A.MONEY2 = B.MONEY2";
                }

                String wdCol = ConvertUtil.toString(param.get("wdCol"));
                if (StringUtils.isNotEmpty(wdCol)) {
                    insertField = wdCol;
                    List<String> wds = (List)Arrays.stream(wdCol.split(",")).filter(StringUtils::isNotEmpty).map(String::trim).collect(Collectors.toList());
                    StringBuilder selectFields = new StringBuilder();
                    StringBuilder conditions = new StringBuilder(condition);
                    Iterator var10 = wds.iterator();

                    while(var10.hasNext()) {
                        String wd = (String)var10.next();
                        selectFields.append(",A.").append(wd);
                        conditions.append(" AND COALESCE(A.").append(wd).append(" ,0) = COALESCE(B.").append(wd).append(",0)");
                    }

                    selectField = selectFields.toString();
                    condition = conditions.toString();
                }

                List<String> replaceTabNameList = new ArrayList();
                replaceTabNameList.add("GT_ZW_WDBILLMX");
                String insertSql = MessageFormat.format(AccComprehensiveQueryDaoConst.MER_JAN_DATA_TO_GT_ZW_WDBILLMX, insertField, selectField, condition);
                log.info(insertSql);
                String deleteSql2 = "DELETE FROM GT_ZW_WDBILLMX WHERE TYPEBZ IS NULL OR TYPEBZ = 1 ";
                log.info(deleteSql2);
            });
        });
    }

    private void handJanuaryDataOfWdBillMxTableForOneDimYwMain(Map<String, Object> param) {
        boolean hasAnalyze = ConvertUtil.toBoolean(param.get("hasAnalyze"));
        if (hasAnalyze) {
            boolean isOneDim = param.get("isYwMainAndOneDim") != null && ConvertUtil.toInt(param.get("isYwMainAndOneDim")) == 1;
            if (isOneDim) {
                
                String wdCol = ConvertUtil.toString(param.get("wdCol"));
                List<String> replaceTabNameList = new ArrayList();
                String insertSql = MessageFormat.format(AccComprehensiveQueryDaoConst.YW_MAIN_DATA_GROUP_TO_GT_ZW_WDBILLMX2, wdCol);
                log.info(insertSql);
                String insertSql2 = MessageFormat.format(AccComprehensiveQueryDaoConst.INSERT_YW_MAIN_DATA_GROUP_TO_GT_ZW_WDBILLMX, wdCol);
                log.info(insertSql2);

            }
        }

    }

    private boolean isNcYe(Map<String, Object> param) {
        Map<String, Object> beginBalanceParam = (Map)param.get("beginBalanceParam");
        return !Objects.isNull(beginBalanceParam) && !beginBalanceParam.isEmpty();
    }

    private String limitHzDataForHzTempTable(Map<String, Object> param, String findOneSql) {
        int limitCount = ConvertUtil.toInt(param.get("hzDataLimit"));
        String dataOption = ConvertUtil.toString(param.get("dataOption"));
        boolean export = ConvertUtil.toBoolean(param.get("export"));
        if (!"MERGEDATA".equals(dataOption) && !export) {
            String resultSql = findOneSql;
            if (limitCount > 0) {
                int isFromAccBalSum = ConvertUtil.toInt(param.get("isFromAccBalSum"));
                boolean isShowAllWd = ConvertUtil.toBoolean(param.get("isShowAllWd"));
                int moneyType = ConvertUtil.toInt(param.get("moneyType"));
                if (isFromAccBalSum != 1 && !isShowAllWd) {
                    if (moneyType == -3) {
                        resultSql = this.handUnionAllSqlForCurAndCommonLimit(param, findOneSql);
                    } else {
                        resultSql = this.buildSqlForCommonLimit(param, findOneSql);
                    }
                } else if (moneyType == -3) {
                    resultSql = this.handUnionAllSqlForCurAndKmLimit(param, findOneSql);
                } else {
                    resultSql = this.buildSqlForKmLimit(param, findOneSql);
                }
            }

            return resultSql;
        } else {
            return findOneSql;
        }
    }

    private String buildSqlForCommonLimit(Map<String, Object> param, String findOneSql) {
        int limitCount = ConvertUtil.toInt(param.get("hzDataLimit"));
        int fromIndex = findOneSql.indexOf("FROM");
        String selectFields = findOneSql.substring(0, fromIndex);
        Pattern pattern = Pattern.compile("[A|Y]\\.[^\\s),]+|DIM[^\\s,]*");
        Matcher matcher = pattern.matcher(selectFields);
        StringBuilder replaceField = new StringBuilder();
        Set<String> set = new HashSet();

        String replaceFieldStr;
        while(matcher.find()) {
            replaceFieldStr = matcher.group();
            if (set.add(replaceFieldStr)) {
                replaceField.append(replaceFieldStr).append(",\n");
            }
        }

        if (!replaceField.toString().contains("A.FOR_CUR")) {
            replaceField.append(" A.FOR_CUR \n");
        }

        replaceFieldStr = replaceField.toString().replaceAll(",$", "");
        if (findOneSql.contains("ACC_OBJ_MER_REL")) {
            replaceFieldStr = replaceFieldStr.toString().replace("A.DIM_VAL", "NVL(F.OBJ_ID1,A.DIM_VAL) DIM_VAL");
        }

        String innerSql = " SELECT " + findOneSql.replace(selectFields, replaceFieldStr + "\n");
        int groupByIndex = innerSql.indexOf("GROUP BY");
        String limitSql = innerSql.substring(0, groupByIndex);
        if (DBUtil.isMySql()) {
            limitSql = limitSql + " LIMIT " + limitCount;
        } else {
            limitSql = limitSql + " AND ROWNUM<= " + limitCount;
        }

        int fromIndex2 = findOneSql.indexOf("FROM");
        int groupByIndex2 = findOneSql.indexOf("GROUP BY");
        String resultSql = findOneSql.substring(0, fromIndex2) + " FROM  (%s) A \n" + findOneSql.substring(groupByIndex2);
        resultSql = this.replaceTsSql(resultSql);
        resultSql = String.format(resultSql, limitSql);
        return resultSql;
    }

    private String buildSqlForKmLimit(Map<String, Object> param, String findOneSql) {
        String sqlTemplate = "FROM \\((.*?)\\) A1";
        Pattern pattern = Pattern.compile(sqlTemplate, 32);
        Matcher matcher = pattern.matcher(findOneSql);
        if (matcher.find()) {
            String subSql = matcher.group(1);
            String sql = findOneSql.replace(subSql, "%s");
            String limitSql = this.buildSqlForCommonLimit(param, subSql);
            String resultSql = String.format(sql, limitSql);
            return resultSql;
        } else {
            return findOneSql;
        }
    }

    private String replaceTsSql(String sql) {
        sql = sql.replace("Y.ZDNAME", "A.ZDNAME");
        return sql;
    }

    private String handUnionAllSqlForCurAndKmLimit(Map<String, Object> param, String sql) {
        if (sql.contains("UNION ALL")) {
            String[] s = sql.split("UNION ALL");
            String findOneSql = this.buildSqlForKmLimit(param, s[0]);
            String findTwoSql = this.buildSqlForKmLimit(param, s[1]);
            return findOneSql + " UNION ALL \n" + findTwoSql;
        } else {
            return sql;
        }
    }

    private String handUnionAllSqlForCurAndCommonLimit(Map<String, Object> param, String sql) {
        if (sql.contains("UNION ALL")) {
            String[] s = sql.split("UNION ALL");
            String findOneSql = this.buildSqlForCommonLimit(param, s[0]);
            String findTwoSql = this.buildSqlForCommonLimit(param, s[1]);
            return findOneSql + " UNION ALL \n" + findTwoSql;
        } else {
            return sql;
        }
    }



    public List<Map> findResultTableListBySql(String sql, Map<String, Object> param) {
        Map<String, Object> params = new HashMap();
        Boolean export = ConvertUtil.toBoolean(param.get("export"));
        if (!export) {
            String accountYear = ConvertUtil.toString(param.get("accountYear"));
            params.put("TYEAR", accountYear);
            params.put("KEY_VALUE", 0);
        }

        List<String> replaceTabNameList = new ArrayList();
        replaceTabNameList.add("GT_ZW_WDBILLMX");
        replaceTabNameList.add("GT_KMDESTTAB");
        return new ArrayList<>();
    }


    private static final String SQL_CLASS = AccComprehensiveQueryDao.class.getName();

    private String dealGldxHbForWdCondition(String selValues, String wdName) {
        if (StringUtils.isNotEmpty(selValues)) {
            String[] arr = selValues.trim().split(",");
            if (DBUtil.isMySql()) {
            }

            String sql = SqlResource.getSql(SQL_CLASS, "sql", new String[]{"wdName", wdName});
            log.info(sql);
            StringBuilder selValueResult = new StringBuilder("");
            int idx = 0;


            return selValueResult.toString();
        } else {
            return selValues;
        }
    }

    public String exportAllDataSql(String sql, Map<String, Object> param, Integer keyValue) {
        String returnFindSql = "";
        String insertSql = "";
        int isForCur = ConvertUtil.toInt(param.get("isForCur"));
        String selectQtWdCol = "";
        if (param.get("wdCol") != null) {
            selectQtWdCol = ConvertUtil.toString(param.get("wdCol"));
        }

        insertSql = MessageFormat.format(AccComprehensiveQueryDaoConst.QUERY_RESULT_INTO_QT_TABLE, sql, selectQtWdCol);
        returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.QUERY_RESULT_FROM_QT_TABLE, ConvertUtil.toString(keyValue), selectQtWdCol);
        if (isForCur == 1) {
            insertSql = MessageFormat.format(AccComprehensiveQueryDaoConst.QUERY_RESULT_INTO_QT_TABLE_FOR_CUR, sql, selectQtWdCol);
            returnFindSql = MessageFormat.format(AccComprehensiveQueryDaoConst.QUERY_RESULT_FROM_QT_TABLE_FOR_CUR, ConvertUtil.toString(keyValue), selectQtWdCol);
        }

        Map<String, Object> params = new HashMap();
        String accountYear = ConvertUtil.toString(param.get("accountYear"));
        params.put("TYEAR", accountYear);
        params.put("KEY_VALUE", keyValue);
        List<String> replaceTabNameList = new ArrayList();
        replaceTabNameList.add("GT_ZW_WDBILLMX");
        replaceTabNameList.add("GT_KMDESTTAB");
        log.info(insertSql);
        return returnFindSql;
    }














    private String getNotNullWdColStr(String wdCol, Map<String, Object> param) {
        if (StringUtils.isEmpty(wdCol)) {
            return "";
        } else {
            List<Map<String, Object>> xjmxSelectWds = (List)param.get("xjmxSelectWd");
            if (!CollectionUtils.isEmpty(xjmxSelectWds)) {
                Map<String, String> choseWdMap = (Map)xjmxSelectWds.stream().collect(Collectors.toMap((e) -> {
                    return ConvertUtil.toString(e.get("wdname"));
                }, (e) -> {
                    return Objects.nonNull(e.get("selvalue")) ? ConvertUtil.toString(e.get("selvalue")) : "";
                }, (k1, k2) -> {
                    return k1;
                }));
                return getNotNullWdColStr2(wdCol, choseWdMap);
            } else {
                wdCol = wdCol.replaceFirst(",", "");
                String[] columns = wdCol.split(",");
                StringBuilder condition = new StringBuilder(" WHERE ");

                for(int i = 0; i < columns.length; ++i) {
                    condition.append("T.").append(columns[i].trim()).append(" IS NOT NULL ");
                    if (i < columns.length - 1) {
                        condition.append(" OR ");
                    }
                }

                return condition.toString();
            }
        }
    }

    private static String getNotNullWdColStr2(String wdCol, Map<String, String> choseWdMap) {
        Stream<String> var10000 = choseWdMap.keySet().stream();
        long count = var10000.filter(wdCol::contains).count();
        if (count != (long)choseWdMap.size()) {
            return " WHERE 0 = 1 ";
        } else {
            wdCol = wdCol.replaceFirst(",", "");
            String[] columns = wdCol.split(",");
            StringBuilder condition = new StringBuilder(" WHERE ");

            for(int i = 0; i < columns.length; ++i) {
                String col = columns[i].trim();
                if (choseWdMap.containsKey(col)) {
                    String value = (String)choseWdMap.get(col);
                    if (Objects.nonNull(value) && StringUtils.isNotEmpty(value)) {
                        condition.append("T.").append(col).append(" IN (").append(value).append(") ");
                    } else {
                        condition.append("T.").append(col).append(" IS NOT NULL ");
                    }

                    if (i < columns.length - 1) {
                        condition.append(" AND ");
                    }
                }
            }

            return condition.toString().replaceAll(" AND $", " ");
        }
    }
}
